Qt-interest Archive, June 2007
popupmenu doesn' t disappear with qwidgetaction
Message 1 in thread
hello,
i have used qwidgetaction to add a custom widget in a qmenu. the menu is
attached to a toolbutton on a toolbar
i want to be able to tear-off the menu so i've subclassed qactionwidget
and implemented createWidget(QWidget *) like this:
QWidget * IconPalette::createWidget(QWidget * parent)
{
QWidget * w = new QWidget(parent);
QGridLayout * layout = new QGridLayout(w);
w->setLayout(layout);
// add buttons to layout
return w;
}
everything works as expected. the only problem i have is that the popup
menu doesn't disappear after clicking on one of the buttons in my widget.
i have connected to the buttons triggered(QAction *) signals in my
subclassed qactionwidget and have called QWidgetAction::trigger() there
but to no effect.
does anyone know how to achieve this (the documentation is very cryptic)?
thanks!
edwin
--
[ signature omitted ]
Message 2 in thread
Edwin Leuven wrote:
> i have used qwidgetaction to add a custom widget in a qmenu. the menu is
> attached to a toolbutton on a toolbar
>
> i want to be able to tear-off the menu so i've subclassed qactionwidget
> and implemented createWidget(QWidget *) like this:
>
> QWidget * IconPalette::createWidget(QWidget * parent)
> {
> QWidget * w = new QWidget(parent);
> QGridLayout * layout = new QGridLayout(w);
> w->setLayout(layout);
> // add buttons to layout
> return w;
> }
>
> everything works as expected. the only problem i have is that the popup
> menu doesn't disappear after clicking on one of the buttons in my widget.
to answer my own question:
subclass the buttons and forward the mouseReleaseEvent:
class MyButton : public QToolButton
{
public:
MyButton(QWidget * parent = 0);
void mouseReleaseEvent(QMouseEvent *event);
};
MyButton::MyButton(QWidget * parent)
: QToolButton(parent)
{
}
void MyButton::mouseReleaseEvent(QMouseEvent *event)
{
// this one triggers the action and untoggles the button
QToolButton::mouseReleaseEvent(event);
// this one forwards the event to the parent
QWidget::mouseReleaseEvent(event);
}
--
[ signature omitted ]