You can use a QToolButton
instead of QPushButton
and add actions to the QToolButton. You should create your custom QWidgetAction
to add to the popup menu.
This is a sample QWidgetAction
:
#include <QWidgetAction>
class myCustomWidgetAction: public QWidgetAction
{
Q_OBJECT
public:
explicit myCustomWidgetAction(QWidget * parent);
protected:
QWidget * createWidget(QWidget *parent);
};
myCustomWidgetAction::myCustomWidgetAction(QWidget * parent):QWidgetAction(parent) {
}
QWidget * myCustomWidgetAction::createWidget(QWidget *parent){
myCustomWidget * widget=new myCustomWidget(parent);
return widget;
}
You can then add your widget to the toolButton to be displayed in a popup menu:
myCustomWidgetAction * widgetAction = new myCustomWidgetAction(this);
ui->toolButton->addAction(widgetAction);
Your custom widget can be a list containing different elements or it can be any other widget. You can also add multiple instances of myCustomWidgetAction
to the toolButton.