PDA

View Full Version : QWidgetAction refuse to disappear on trigger()



dave
17th May 2010, 20:19
I have a a QWidgetAction which holds a QWidget composed of a QLineEdit and a QPushButton. Once the user press the button the QWidgetAction call the trigger slot.

Now I have a QMenu which I activate with exec. The problem is that even though trigger is called (I've connected it to a print function as well to check) the menu won't close.

Any idea why? I'm at my wits' end.

(Searching on the net I have found other people (http://lists.trolltech.com/pipermail/qt-interest/2010-March/020001.html) with the same problem, but no answers.)

ChrisW67
17th May 2010, 23:08
Have you got a small example program demonstrating the problem that you can post here?

dave
18th May 2010, 00:36
Have you got a small example program demonstrating the problem that you can post here?

I can't post my code since I it's not small and I can't really separate it into something manageable. So I took Qt Menus example and modified it to show the problem: The relevant code is in the testaction.cpp, testaction.h and in the function contextMenuEvent in the mainwindow.cpp file.

To see the behavior: compile it, run it, right click anywhere in the program, go into the submenu and try the ok button.

I really hope you can shed some light on this.

dave
21st May 2010, 01:41
Anybody? Anything?

norobro
21st May 2010, 03:19
Hi Dave,

Don't know whether this will solve the problem with your app but it works on your example. I got the menu to hide when the pushbutton is clicked by doing the following:
Changed the connect statement in TestAction::createWidget() to this:
connect(wgt->btn, SIGNAL(clicked()), this, SIGNAL(triggered()));
Created "menu" on the heap in MainWindow::contextMenuEvent() and added this connect statement:
connect(te, SIGNAL(triggered()), menu, SLOT(hide()));

dave
23rd May 2010, 01:09
It works. but now exec return NULL. Will have to work around it. I really start to wonder if it is a bug int Qt or I'm just not using it right...