[Interest] adding a drop-down list with options to a QPushButton: TapAndHold gesture or QPushButton::addActions?

René J.V. Bertin rjvbertin at gmail.com
Sat Mar 11 11:07:42 CET 2017


Hi,

I have a QPushButton (defined in a .ui file) triggering an update function to which I'd l'd like to add a way to control a parameter of that update in the form of a list of different values to chose from.

The interface I have in mind is
- regular click on the button: trigger the default update (= with the current parameter value)
- long click OR right-click: present a drop-down list with the parameter values; picking one triggers the update with the selected parameter value.

What's the cleanest way to implement this?

The parameter values to chose from can be a fixed list so if Designer allows this interface addition could be defined completely in the .ui file. Is that possible - set the contextMenuPolicy to ActionsContextMenu and then define individual QActions that each call the parameter setter method with the corresponding value?

Or would it be cleaner to use a regular dynamically created context menu in an event handler and if so, is there any difference in implementation complexity between a context menu event (right-click) or TapAndHold gesture event?

Thanks,
René



More information about the Interest mailing list