[Qt-interest] Extending the context menu of a QDoubleSpinBox

Emmanuel Mayssat emayssat at gmail.com
Mon Jan 16 17:54:39 CET 2012


The best way I found to implement this is to subclass QDoubleSpinBox
and reimplement the contextMenuEvent method following the one defined
in QAbstract

http://cep.xor.aps.anl.gov/software/qt4-x11-4.2.2-browser/d5/d8d/qabstractspinbox_8cpp-source.html

    def contextMenuEvent(self, event):
        menu = self.lineEdit().createStandardContextMenu()
        menu.addSeparator()
        se = self.stepEnabled()
        self.stepUpAction.setEnabled(se & QAbstractSpinBox.StepUpEnabled)
        self.stepDownAction.setEnabled(se & QAbstractSpinBox.StepDownEnabled)
        self._addActions_(menu, ( self.setStepSizeAction, None,
self.stepUpAction, self.stepDownAction, self.newAction))
        menu.exec_(event.globalPos())




On Sat, Jan 14, 2012 at 3:12 AM, Bo Thorsen <bo at fioniasoftware.dk> wrote:
> Den 13-01-2012 19:13, Emmanuel Mayssat skrev:
>> Hello,
>>
>> I would like to extend the menu of q QDoubleSpinBox.
>> I can modify the contextMenuEvent and trigger my custom menu.
>> But I would like my custom menu to be appended to the standard menu.
>>
>> With some other widget , I believe it is possible to use
>> the createStandardContextMenu method, but that method doesn't seem to
>> exist for QDoubleSpinBox.....
>
> Try subclassing it and implement the event handler, listen for children
> added, check if a new child is a QMenu...
>
> It's a bit of an evil hack, but sometimes you have to do stuff like this.
>
> Bo Thorsen,
> Fionia Software.
>
> --
>
> Expert Qt and C++ developer for hire
> Contact me if you need expert Qt help
> http://www.fioniasoftware.dk
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list