[Qt-interest] QWidgetAction stays visible after triggered() signal and trigger() slot.
John Weeks
john at wavemetrics.com
Tue Jul 19 19:47:10 CEST 2011
Mistakenly sent only to Davor. I *thought* I hit Reply to All, but apparently not...
Thank you, Davor.
Unfortunately there seems to be something missing that I can't figure out...
Is the QWidgetAction added to TreeViewMenu (for instance, using addAction)?
Did you have to write some code for TreeViewMenu or your QWidgetAction to cause TreeViewMenu to emit the triggered() signal?
> PS Nice company!
Thank you!
Regards, John Weeks
> I remember going through the Qt code, trying to find the problem. As far as I can see now, I used this:
>
>
> connect(this, SIGNAL(triggered(QAction*)), this, SLOT(slot_actionTriggered(QAction *)))
>
>
>
> void TreeViewMenu::slot_actionTriggered(QAction *action)
>
>
> {
>
> if (action == m_action) {
>
>
> // HideEvent zorgt ervoor dat menu onzichtbaar wordt en
>
> // menu uit zijn eventLoop komt. = HideEvent makes sure that the menu becomes invisible and exits from its eventloop...
>
>
> hideEvent(new QHideEvent());
>
>
> }
>
> }
>
> Hopefully it is of any use.
> Kind regards,
> Davor
>
> PS Nice company!
>
> On 14 July 2011 17:48, John Weeks <john at wavemetrics.com> wrote:
> I was wondering if you ever found a solution to this problem.
>
> I have a similar problem- a cascade of contextual menus, at the innermost level a QWidgetAction that displays a custom color picker inside the menus. After trying numerous variations, I finally concluded that the only solution was to have the widget inside the QWidgetAction emit a signal, connect that to a slot in the code that puts up the menu, and use that connection to call QMenu::close on the top-level menu. Here's a screen shot of the menus:
>
> <PastedGraphic-2.png>
>
> The essence of the code is like this:
>
> In the constructor for the tool-bar-like window:
>
> ColorPickerAction = new WMColorPickerAction(this);
> connect(ColorPickerAction, SIGNAL(colorChanged(const QColor)), this, SLOT(onColorChanged(const QColor)));
> CursorColorMenu.addAction(ColorPickerAction);
>
> The color picker itself uses a QTableWidget with custom delegate. It emits a signal when a color cell is clicked:
>
> void WMColorPickerWidget::onCurrentItemChanged(QTableWidgetItem * current, QTableWidgetItem * previous) {
> Q_UNUSED(previous);
> if (current) {
> emit selectedColorChanged(current->backgroundColor()); // TO DO: Igor will need RGB16Color, not QColor
> }
> }
>
> The toolbar-like window (InfoPanel) ultimately gets a signal from that:
>
> void
> InfoPanel::onColorChanged(const QColor theColor)
> {
> changeCursorColor(theColor, menuCursorNum);
> TraceNameMenu->close();
> }
>
> TraceNameMenu is the top-level menu, the one with "Style" at the top.
>
>
> Regards, John Weeks
>
>
>> What I need is a QMenu that displays a button, and when I press the button,
>> it triggers an action and goes away. I have managed all except the last
>> part: the menu doesn't disappear (more specifically: the program blocks
>> execution on QMenu::exec(), no matter if trigger() is executed or not.)
>>
>> What is the correct (!) way to let QWidgetAction behave like a simple
>> QAction in QMenu (i.e. to remove the widget after triggering the action.)?
>> Take the the example below as a starting point:
>>
>> class A : public QWidgetAction {
>> public:
>> A(QObject *parent = 0) : QWidgetAction(parent){
>> QPushButton *b = new QPushButton("BUTTON");
>> setDefaultWidget(b);
>>
>> connect(b, SIGNAL(clicked()),
>> this, SLOT(trigger())); //Docs suggest executing this
>> connect(b, SIGNAL(clicked()),
>> this, SIGNAL(triggered()));
>> }
>> };
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110719/00660b0e/attachment.html
More information about the Qt-interest-old
mailing list