-
QDoubleSpinBox
I want to be able to use a custom contextMenu in a QDoubleSpinBox. So it seemed the best way to do that is to sublass a QDoubleSpinBox and subclass a QLineEdit.
Using the sub classed QLineEdit to create my contextMenu needs as well as QValidator etc.
Using to set my custom QLineEdit in my custom QDoubleSpinBox does not appear to provide the result I was looking for.
Using lineEdit() shows that my custom QLineEdit is installed but I am not getting my custom contextMenu.
Is this the wrong approach?
Bob
-
Re: QDoubleSpinBox
Reimplement contextMenuEvent for the subclassed spinbox (and not its lineedit) and make sure the context menu policy is set appropriately.
-
Re: QDoubleSpinBox
I understand the contextMenu is needed for the SpinBox but all its actions are from the QLineEdit.
1) I could make the QMenu in the QLineEdit public and just use it inside the SpinBox.
2) I could make public the actions from the QLineEdit and create the contextMenu inside the Spinbox.
Qt::DefaultContextMenu appears to be the only logical choice since Qt::ActionsContextMenu would just display the QActions but I would lose the ability to layout seperator, order, etc.
I guess my question is 1 or 2 the proper way to implement this or is there a 3rd option I am missing?
Bob
-
Re: QDoubleSpinBox
3) call QLineEdit::createStandardContextMenu() to get the standard context menu and extend it with your custom actions like QAbstractSpinbox::contextMenuEvent() does (see src/gui/widgets/qabstractspinbox.cpp for more details).
-
Re: QDoubleSpinBox
The problem is the standard menu has options I don't want. I think I have it working, was more worried about doing this the "proper" way then some kludge of my warped coding standards.
Thanks for the help.
-
Re: QDoubleSpinBox
So when you have the menu, delete/hide/disable those you don't want.
-
Re: QDoubleSpinBox
It's the "insert Unicode control character" that I do not need and just seems to add confusion. I also like icons associated with the cut,paste,etc.
Visual cues help in the cases where native language support might not be available to someone and they are making due with whatever the closest language is.
Bob
EDIT: Its going to get real crazy soon, since I need to figure out a way to support HEX only or INT only in the same spinbox and figure out a way for it to know which is which.
EDIT2: Just noticed something interesting. If you use the arrow button to adjust the spinboxs value it does not trigger a undo/redo. You would think any change would trigger the framework (This is in the standard contextMenu).