Jim Prouty | 9 Oct 20:29 2012

Can't get menu with QWidgetAction to close after click! (Mac OS 10.6.8, Qt 4.8.3)

In this test program (Qt 4.8.3 on Mac OS X 10.6.8), I've got one QMenu added to the menubar, and the menu has
several QWidgetActions, including one that has a Done QPushButton and a QSpinBox.

Having connected the QPushButton to a slot, I'm trying to get the menu to close up after the button has been
clicked(), but the menu resolutely stays visible:


Based on Google search results, I've programmed my _onPushButton() slot to call QMenu::close() on the
added menu.

I've tried using a queued connection hoping to do an end run around the event handling, but neither direct
nor queued connections succeed in closing the menu.

I've checked that the slot is getting called (qDebug() is printing).

What am I doing wrong here?

(And yes, I see that there are other menu issues with the program; Qt for Mac seems a bit neglected.)

main.cpp:

#include <QApplication>
#include <QLabel>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QDebug>
(Continue reading)

Stephen Chu | 9 Oct 21:31 2012

Re: Can't get menu with QWidgetAction to close after click! (Mac OS 10.6.8, Qt 4.8.3)

Are you sure you want a push button or a text entry field in the menu
from the menu bar?

It's, hmm, very different way of building an UI. Especially on a Mac.

On 10/9/12 2:29 PM, Jim Prouty wrote:
> In this test program (Qt 4.8.3 on Mac OS X 10.6.8), I've got one
> QMenu added to the menubar, and the menu has several QWidgetActions,
> including one that has a Done QPushButton and a QSpinBox.
>
> Having connected the QPushButton to a slot, I'm trying to get the
> menu to close up after the button has been clicked(), but the menu
> resolutely stays visible:
>
>
>
>
>
> Based on Google search results, I've programmed my _onPushButton()
> slot to call QMenu::close() on the added menu.
>
> I've tried using a queued connection hoping to do an end run around
> the event handling, but neither direct nor queued connections succeed
> in closing the menu.
>
> I've checked that the slot is getting called (qDebug() is printing).
>
> What am I doing wrong here?
>
> (And yes, I see that there are other menu issues with the program; Qt
(Continue reading)

Jim Prouty | 10 Oct 00:39 2012

Re: Can't get menu with QWidgetAction to close after click! (Mac OS 10.6.8, Qt 4.8.3)


On Oct 9, 2012, at 12:31 PM, Stephen Chu wrote:

> Are you sure you want a push button or a text entry field in the menu
> from the menu bar?
> 
> It's, hmm, very different way of building an UI. Especially on a Mac.
> 

That's only a test program; the real application has a color swatch in the widget that gets clicked.

But the issue is the same (and this sample code is simpler): after interacting with the QWidgetAction
inserted into a menu, how can I get the menu to go away?

Clicking in a normal action (menu item) dismisses the menu after emitting triggered().

I'd like the same behavior for my QWidgetAction, but it just sits there like a bump on a log whether it
contains a button or a color swatch.

--Jim

========================================================================

Jim "How does it work?" Prouty

Voice: (503) 620-3001, FAX: (503) 620-6754
Makers of IGOR Pro, scientific data analysis and graphing for Mac and PC
http://www.wavemetrics.com

(Continue reading)

Alex Malyushytskyy | 10 Oct 02:23 2012
Picon

Re: Can't get menu with QWidgetAction to close after click! (Mac OS 10.6.8, Qt 4.8.3)

On Windows, QT 4.7 it works as as expected.
I guess problem is specific to MAC

Alex

On Tue, Oct 9, 2012 at 3:39 PM, Jim Prouty <jim <at> wavemetrics.com> wrote:
>
> On Oct 9, 2012, at 12:31 PM, Stephen Chu wrote:
>
>> Are you sure you want a push button or a text entry field in the menu
>> from the menu bar?
>>
>> It's, hmm, very different way of building an UI. Especially on a Mac.
>>
>
> That's only a test program; the real application has a color swatch in the widget that gets clicked.
>
> But the issue is the same (and this sample code is simpler): after interacting with the QWidgetAction
inserted into a menu, how can I get the menu to go away?
>
> Clicking in a normal action (menu item) dismisses the menu after emitting triggered().
>
> I'd like the same behavior for my QWidgetAction, but it just sits there like a bump on a log whether it
contains a button or a color swatch.
>
> --Jim
>
> ========================================================================
>
> Jim "How does it work?" Prouty
(Continue reading)

Alex Malyushytskyy | 10 Oct 02:29 2012
Picon

Re: Can't get menu with QWidgetAction to close after click! (Mac OS 10.6.8, Qt 4.8.3)

By the way try to call   QAction->trigger();
in _onPushButton(bool b)

If MAC implementation depends on this signal it definitely should
solve the problem.
By default QWidgetAction does not call it:

"Note that it is up to the widget to activate the action, for example
by reimplementing mouse event handlers and calling
QAction::trigger()."

Alex

On Tue, Oct 9, 2012 at 5:23 PM, Alex Malyushytskyy <alexmalvtk <at> gmail.com> wrote:
> On Windows, QT 4.7 it works as as expected.
> I guess problem is specific to MAC
>
> Alex
>
>
> On Tue, Oct 9, 2012 at 3:39 PM, Jim Prouty <jim <at> wavemetrics.com> wrote:
>>
>> On Oct 9, 2012, at 12:31 PM, Stephen Chu wrote:
>>
>>> Are you sure you want a push button or a text entry field in the menu
>>> from the menu bar?
>>>
>>> It's, hmm, very different way of building an UI. Especially on a Mac.
>>>
>>
(Continue reading)

Jim Prouty | 10 Oct 03:25 2012

Re: Can't get menu with QWidgetAction to close after click! (Mac OS 10.6.8, Qt 4.8.3)


On Oct 9, 2012, at 5:29 PM, Alex Malyushytskyy wrote:

> By the way try to call   QAction->trigger();
> in _onPushButton(bool b)
> 
> If MAC implementation depends on this signal it definitely should
> solve the problem.
> By default QWidgetAction does not call it:
> 
> "Note that it is up to the widget to activate the action, for example
> by reimplementing mouse event handlers and calling
> QAction::trigger()."
> 

This does not close the menu, either. Again, on Macintosh (using Cocoa menus).

Though I'm not using the signal from the QWidgetAction in the test case, I amended the code to try this idea out.

I stashed the SpinBoxAction (derived from QWidgetAction) in the application's _wAction3 member
variable and called trigger() on it in the _onPushButton() slot:

     // Widget Action 3
    SpinBoxAction * spinBoxAction = new SpinBoxAction(QLatin1String("Done"),menu);
    app._wAction3= spinBoxAction;
    menu->addAction( spinBoxAction );

    if( QWidget *widget= spinBoxAction->requestWidget(menu) ) {
        if( QPushButton *button = widget->findChild<QPushButton *>() ) {
            QObject::connect(button, SIGNAL(clicked(bool)), &app, SLOT(_onPushButton(bool)));
(Continue reading)


Gmane