Results 1 to 7 of 7

Thread: Vertical QComboBox

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Smile Vertical QComboBox

    Hello!

    I'ld like to have a vertical QComboBox, instead of the traditional horizontal one. Is there a way to do this with QComboBox, or will I heave to reimplement it?

    If I need to reimplement, I imagine I'll have to edit the paintEvent() method. But how exactly should I do this? (sorry, not much experience here with QPainter and related...).



    Thanks,

    Momergil

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,534
    Thanks
    13
    Thanked 1,576 Times in 1,505 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Vertical QComboBox

    How is a "vertical QComboBox" supposed to work?

  3. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Vertical QComboBox

    Quote Originally Posted by ChrisW67 View Post
    How is a "vertical QComboBox" supposed to work?
    The same way as the normal QComboBox, just rotated to the left or to the right (at least I pretend to show only images inside the QComboBox, like discussed here [http://www.qtcentre.org/threads/5800...tyle?p=258787], so there is no necessity for this case to re-rotate the widget that appears with the combobox options when it is clicked).

    Attachment 10032

    (imagine that i want to put it inside a QToolBar located at the right of a QMainWindow)
    (and one more thing: this rotate capacity must be reusable once the QComboBox is draw, since the QToolBar may have its location changed from the right to up or down of the QMainWindow and, in such positions, the combobox needs to be horizontally displayed as usual)

  4. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Vertical QComboBox

    So, any guesses? :x

    I tried to find a solution in Qt Creator's examples, but it seems all of them show how to use QTransform and how to reimplement paintEvent(QPaintEvent*) when is the case of rotating a given, draw-by-myself widget, never a default Qt widget such as QComboBox - not to mention I couldn't understand much of the code I saw ^^

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,357
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Vertical QComboBox

    Even if you derive from QComboBox, you will still have to overwrite a lot of things and implement them your own, at least painting and event handling.

    Since you would have to "work around" assumptions in the QComboBox code this is probably more work then to implement your custom combobox yourself.
    Especially since you might know restrictions that can make certain things unnecessary, e.g. not needing to handle text input if your comboboxes aren't editable.

    Cheers,
    _

  6. #6
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Vertical QComboBox

    Quote Originally Posted by anda_skoa View Post
    Even if you derive from QComboBox, you will still have to overwrite a lot of things and implement them your own, at least painting and event handling.

    Since you would have to "work around" assumptions in the QComboBox code this is probably more work then to implement your custom combobox yourself.
    Especially since you might know restrictions that can make certain things unnecessary, e.g. not needing to handle text input if your comboboxes aren't editable.

    Cheers,
    _
    \o/ All of this just to be able to rotate a QComboBox 90º clockwise or counterclockwise???? o.O I though it would be just a matter of reimplementing the paintEvent() method telling to draw some points in a different place \o/

    Well, I'll stand in the hope somebody will come with an easier solution (a complete working code?) than to create my entirely new combo box ^^ Too much work for something that is a detail in my current project situation

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,357
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Vertical QComboBox

    Quote Originally Posted by Momergil View Post
    \o/ All of this just to be able to rotate a QComboBox 90º clockwise or counterclockwise???? o.O I though it would be just a matter of reimplementing the paintEvent() method telling to draw some points in a different place \o/
    Well, yes.
    But you to also report a different geometry, e.g. different sizeHint() otherwise the widget would still reserve horizontal space.
    If the combobox is editable, you would also have to reimplement mouse event handling, otherwise text selection will not work (mouse left<->right no longer moves from character to character).
    If the popup can only be triggered by clicking in a certain area, then this also needs to check the new coordinates.

    Quote Originally Posted by Momergil View Post
    Well, I'll stand in the hope somebody will come with an easier solution (a complete working code?) than to create my entirely new combo box ^^ Too much work for something that is a detail in my current project situation
    You can certainly try deriving from QComboBox and just reimplementing all the necessary methods.

    The initial implementation might be less work and might even work as expected, but this kind of "interfering" with a widget's base implementation can sometimes lead to all kinds of hard to debug and fix problems.

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    Momergil (15th February 2014)

Similar Threads

  1. Qt with vertical scroll
    By psarangi in forum Qt Programming
    Replies: 3
    Last Post: 11th December 2013, 10:33
  2. vertical slider
    By TomASS in forum Newbie
    Replies: 4
    Last Post: 29th November 2009, 00:30
  3. vertical scroll bar in Qt box.
    By rajveer in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2008, 07:41
  4. Vertical QTabBar
    By OriginalCopy in forum Qt Programming
    Replies: 4
    Last Post: 5th November 2007, 13:24
  5. Vertical QLabel
    By ToddAtWSU in forum Qt Programming
    Replies: 4
    Last Post: 12th September 2006, 14:14

Tags for this Thread

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.