PDA

View Full Version : Vertical QComboBox



Momergil
10th February 2014, 01:03
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

ChrisW67
10th February 2014, 04:46
How is a "vertical QComboBox" supposed to work?

Momergil
10th February 2014, 10:54
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/58009-QComboBox-to-show-Qt-PenStyle?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).

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)

Momergil
14th February 2014, 00:34
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 ^^

anda_skoa
14th February 2014, 09:00
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,
_

Momergil
14th February 2014, 11:22
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 :)

anda_skoa
14th February 2014, 13:19
\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.



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,
_