简体   繁体   English

我创建了一个QToolButton,标签上将包含“…”,但看起来Qt删除了它们,对吗?

[英]I created a QToolButton and the label would include “…” but it looks like Qt removes them, is that right?

I use the following code, the first part, creating the QToolButton, is from Designer/moc, the rest I added. 我使用以下代码,第一部分创建QToolButton,来自Designer / moc,其余部分来自我。

// Moc part
QToolButton * f_tool_button = new QToolButton(bottom_grid);
f_tool_button->setObjectName(QStringLiteral("f_tool_button"));
f_tool_button->setText(QApplication::translate("MainWindow",
                                               "Tool Button...", 0));

// What I added
f_action = new QAction(this);
f_action->setObjectName(QStringLiteral("f_action"));
f_action->setText(QApplication::translate("MainWindow",
                                          "&Click...", 0));

f_menu.reset(new QMenu("Tool Button Menu ...", this));
f_menu->addAction(f_action);

f_tool_button->setDefaultAction(f_menu->menuAction());

If I don't call setDefaultAction() , the title appears as expected. 如果我不调用setDefaultAction() ,则标题将按预期显示。

When I add the default action, the label seems to be replaced by the f_menu title, "Tool Button Menu ..." (I put a somewhat different label on purpose). 当我添加默认操作时,标签似乎已被f_menu标题“工具按钮菜单...”替换(我故意放了一些不同的标签)。 But somehow the "..." gets removed from the name. 但是以某种方式从名称中删除了“ ...”。

Any idea about this problem? 关于这个问题有什么想法吗? Is that a special Qt feature? 这是Qt的特殊功能吗?

The QToolButton displays text from QAction 's iconText property (not text ). QToolButton显示来自QActioniconText属性的 text (不是text )。 text is meant to be used in menu entries, whereas iconText is meant to be displayed in tool bars. text用于菜单项,而iconText用于显示在工具栏中。 When not set, iconText is a stripped version of text . 未设置时, iconTexttext的剥离版本。

To override the default behavior of stipping text to generate iconText , you can set the desired iconText for your QAction using QAction::setIconText() (ie f_action->setIconText("Click..."); right after your f_action->setText call). 要覆盖点画text的默认行为以生成iconText ,可以使用QAction::setIconText() (即f_action->setIconText("Click...");为您设置QAction所需的iconText f_action->setIconText("Click..."); f_action->setTextf_action->setText呼叫)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM