Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Hide current selection in QComboBox [SOLVED]



  • Is there a way to style a combobox such that it will hide the lineedit that displays the currently selected option? When the combobox is inactive, the only thing I want visible is the downarrow. When the user clicks the control, then the popup list displays. Is this possible or do I have to create my own widget?



  • You can use functions ( but you'll have to inherit QComboBox and write your own widget):
    "QComboBox::focusInEvent":http://qt-project.org/doc/qt-4.8/qcombobox.html#focusInEvent
    "QComboBox::focusOutEvent()":http://qt-project.org/doc/qt-4.8/qcombobox.html#focusOutEvent

    Change width of the widget and if necessary, add "blank" item to you widget and select it if text is still visible.
    Without reimplementing the widget it will be very difficult to create, because there isn't appropriate signal for lost focus.

    Regards,
    Jake



  • So your users are not allowed to see what they've selected?



  • [quote author="Volker" date="1334697548"]So your users are not allowed to see what they've selected?[/quote]

    Yes, that's right. As i'm going to use it, the combobox doesn't represent a static setting but rather a list of actions the user can take. For example the list options will be something akin to "Turn on" and "Turn off" etc, and my application will take the appropriate action when the selection is made. There is no "current setting" as such. If I could set the displayRect to 0 for the textEdit that displays the current setting then that would do the trick, but I don't know if that's available as a style property.


  • Moderators

    So, you'd like a popup menu, then?



  • Looks like the perfect use case for a QToolButton with a popup menu.



  • Uh, yeah. QMenu it is. Thanks, I didn't know about that widget.


  • Moderators

    We're glad to help! Good luck!

    Be sure and edit the title of the thread to add [Solved]. Thanks!


Log in to reply