Results 1 to 7 of 7

Thread: QDoubleSpinBox

  1. #1
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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
    Qt Code:
    1. setLineEdit()
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDoubleSpinBox

    Reimplement contextMenuEvent for the subclassed spinbox (and not its lineedit) and make sure the context menu policy is set appropriately.

  3. #3
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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).
    J-P Nurmi

  5. #5
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDoubleSpinBox

    So when you have the menu, delete/hide/disable those you don't want.

  7. #7
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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).
    Last edited by coderbob; 20th March 2008 at 11:39.

Similar Threads

  1. Validator for QDoubleSpinBox
    By ehamberg in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2008, 11:37
  2. Qt4.2.2 QDoubleSpinBox QSpinBox
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2007, 21:27
  3. [SOLVED] Remove the +/- buttons of a QDoubleSpinBox?
    By hickscorp in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2007, 15:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.