简体   繁体   English

qt5结合QGroupBox和QPushButton

[英]qt5 Combine QGroupBox and QPushButton

I'm trying to create a button with a drop-down list but at the same time, I want the current selected text to be able to activated like a QPushButton. 我正在尝试创建一个带有下拉列表的按钮,但与此同时,我希望当前选择的文本能够像QPushButton一样被激活。 Here are a couple of pics of what I'm looking for, before and after. 这是我正在寻找的前后几张照片。 (Line from MS Paint) (MS Paint的资料行)

I want to have it so if the user clicks to the left of the line, it will resend the signal of whatever item is shown. 我想要它,因此如果用户单击该行的左侧,它将重新发送显示的任何项目的信号。 If the user clicks the drop-down arrow, that list will show up and from then on will act like a normal Group Box until another Item is selected. 如果用户单击下拉箭头,将显示该列表,从那时起,它将像普通的“组框”一样工作,直到选择了另一个项目。

http://imgur.com/a/tFoLv http://imgur.com/a/tFoLv

You can use a QToolButton and a QMenu for it: 您可以QMenu使用QToolButtonQMenu

QToolButton *btn = new QToolButton();
btn->setPopupMode(QToolButton::MenuButtonPopup);

QMenu *btnMenu = new QMenu;
QAction *action1 = btnMenu->addAction("action1");
QAction *action2 = btnMenu->addAction("action2");
btn->setMenu(btnMenu);

connect(btn, SIGNAL(clicked()), this, SLOT(btnSlot()));
connect(action1, SIGNAL(triggered()), this, SLOT(action1Slot()));
connect(action2, SIGNAL(triggered()), this, SLOT(action1Slot()));

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

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