gpt4 book ai didi

c++ - Q工具栏 : Displaying the menu when toolbutton is pressed - DownArrow Issue

转载 作者:行者123 更新时间:2023-11-28 07:13:15 25 4
gpt4 key购买 nike

目前我的代码中有这样的东西:

    QMenu *mabout = new QMenu("About");
QToolButton* tb_about = new QToolButton();
QAction *test= new QAction(mabout);
test->setText("Test");
mabout->addAction(test);
tb_about->setText(mabout->title());
tb_about->setMenu(mabout);
tb_about->setPopupMode(QToolButton::MenuButtonPopup);
ui.toolBar->addWidget(tb_about);

现在,它给了我以下信息:

enter image description here

现在,我想在单击“关于”按钮或向下箭头时显示下拉菜单。但是,当我点击关于文本时没有任何反应。这是它的样子:

enter image description here

没有东西掉下来。只有当我真正点击向下箭头时才会有东西掉下来。有什么方法可以在按下向下箭头时使下拉菜单下降?

最佳答案

我建议您使用 QPushButton 而不是 QToolButton。这是一个工作示例:

QMainWindow window;
QVBoxLayout *layout = new QVBoxLayout();

QPushButton *button = new QPushButton( "Menu button" );
QMenu *menu = new QMenu();

button->setMenu( menu );
menu->addAction( "teste1" );
layout->addWidget( button );

window.setCentralWidget( new QWidget() );
window.centralWidget()->setLayout( layout );
window.show();

关于c++ - Q工具栏 : Displaying the menu when toolbutton is pressed - DownArrow Issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20641809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com