Query regarding aboutToShow signal of Qmenu widget.
-
I have three menus in menu bar like below :
File , Edit and About
In File and Edit i have added Qactions but in About I simply added code to call function aboutclick() which will call the code to show the About Dialog Box.Currently I am using aboutToShow using connct to call my aboutclick() function to show the dialog box.But what is happening is When I click on File and then mouse hover over on About the about dialog box is shown.
I noticed that this is property of QMenu that is if we click one menu and then mouse hover other menu then abouttoShow signal is released hence the dialog box is appeared.
I want that when I just click About in Menu bar then only Dialog box should appear.
Please note that I am using design view to create UI.
-
@Ayush-Gupta said in Query regarding aboutToShow signal of Qmenu widget.:
I want that when I just click About in Menu bar then only Dialog box should appear.
Why not simply create one more action for
About
as you created forFile
andEdit
?
aboutToShow()
says "This signal is emitted just before the menu is shown to the user" which u do not need. -
@Ratzz But that action will displayed as drop down of About. I don't want that I just when I click About it should display the dialog box irrespective if we click other menu items.
-
But that action will displayed as drop down of About.
Not sure what you have done & indented to do. If your intent is to show the dialog when you click on about action, as @Ratzz suggested, you can add three different actions & connection to slot. Inside the slot you can show any dialog you want. If not show the image of what you are planning to achieve.
-
@dheerendra I mean if I add action in About it will show context menu when I click on About.
Suppose I added Action About1 in About then when I click About it will show About1 as context Menu option. as per my understanding?If not please let me know how can I add action and it should be not visible in UI and just clickin on About it will show dialog...how can i do this through programming
-
Add this in construction.
connect(ui->aboutAction,&QAction::triggered, this,&MyWidget::showAbout)MyWidget::showAbout() {
// Create any dialog
// show it
}You can connect signal/slot from Designer also. I'm showing you example from code.
-
@dheerendra I am using design view. And I do not want that action to be displayed in menu. Where and how should i create the action and attach to the about menu.
-
How are you adding the about menu option ? Can you tell ?
-
@Ayush-Gupta said in Query regarding aboutToShow signal of Qmenu widget.:
when I click About it should display the dialog box irrespective if we click other menu items.
U can create an
QAction
to the menubar directly.
Your About menu will always be the last menu . Just try to add from code and connect toaboutclick()
-
@dheerendra I am adding through design view of QT.
@Ratzz Can I add QAction to the About menu using progamming even I if i am using design view
-
@Ayush-Gupta said in Query regarding aboutToShow signal of Qmenu widget.:
Can I add QAction to the About menu using progamming even I if i am using design view
I think u can do in two ways
1)Using CodeQMenuBar *m = this->menuBar(); QAction *aboutMenu = new QAction("About"); connect(aboutMenu, &QAction::triggered, this, &MainWindow::aboutclick); m->addAction(aboutMenu);
- Using designer- Add an menu then connect to your slot
connect(ui->menuAbout,&QMenu::aboutToShow,this,&MainWindow::aboutclick);
-
Can I add QAction to the About menu using progamming even I if i am using design view
You can do it. That is the code I wrote and showed you.