c++ - How can I add custom widget as Popup menu for ToolButton? -
i have created custom widget,it has displayed popup menu when click on toolbutton. how can in qt 5.1.1?
you should create custom qwidgetaction add popup menu.
this 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 add widget tool button displayed in popup menu:
mycustomwidgetaction * widgetaction = new mycustomwidgetaction(this); ui->toolbutton->addaction(widgetaction); mycustomwidget can widget. can add multiple instances of mycustomwidgetaction toolbutton.
Comments
Post a Comment