[Qt-interest] How can I pop-up a menu when I clikcked a button?
Kermit Mei
kermit.mei at gmail.com
Tue Jun 9 04:01:05 CEST 2009
Hello,community!
I need to use a button to pop-up a menu. I can't use MenuBar, because it
can't show as a icon. So I set a button, and connect it to a slot
showMenu():
void MainWidget::showMenu() {
QWidget *senderWidget = qobject_cast<QWidget *>(sender());
if(senderWidget == 0)
return;
QMenu menu(this);
foreach(QAction *act,confActions)
menu.addAction(act);
menu.exec(senderWidget->pos());
}
But, when I click the button, the menu always pop-up out of the current
Widget when I move the widget. I hope the menu can be inside the widget
which include the button.
Thanks.
Kermit
More information about the Qt-interest-old
mailing list