Results 1 to 7 of 7

Thread: QcomboBox hide the drop down arrow

  1. #1
    Join Date
    Feb 2007
    Posts
    39
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default QcomboBox hide the drop down arrow

    There's any way to hide the drop down arrow of a QcomboBox ?

    I've small cells (with QcomboBox's) in a qTableview, and when i click on them all cell size is occupied with the drop down arrow hiding the first item of the list which looks ugly.

    I hope i had explained this well, if not i can attach some screenshots. Thanks in advance.

  2. #2
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QcomboBox hide the drop down arrow

    QComboBox is mainly all about that dropdown arrow, so I guess you can't hide it. But you can use QLineEdit + QCompleter which shall give you basically an effect you are expecting.

  3. #3
    Join Date
    Feb 2007
    Posts
    39
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QcomboBox hide the drop down arrow

    Just took a look at QCompleter but i guess it won't work in this case, my QCombobox list only have Icon images and QCompleter seems to be only for text? correct me if i'm wrong?

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QcomboBox hide the drop down arrow

    QCompleter isn't a widget (it doesn't inherit QWidget) but its useful if you want a drop down list of results (for a combobox, for example).

    Maybe you can override the paintEvent of QComboBox, or perhaps use a QLineEdit + QListView if you want to do all the work yourself.

  5. #5
    Join Date
    Jan 2011
    Posts
    1
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Lightbulb Re: QcomboBox hide the drop down arrow

    It's simply!

    yourCombo->setStyleSheet ("QComboBox::drop-down {border-width: 0px;} QComboBox::down-arrow {image: url(noimg); border-width: 0px;}");

    Look at 'image: url(noimg)' - "noimg" just dummy name, not really link to image, Qt cant load it and there is no fucking arrow!

    For hiding border use the 'border-width' property.

    Profit

  6. #6
    Join Date
    Mar 2016
    Location
    Syracuse, NY, USA
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QcomboBox hide the drop down arrow

    I know this is an old thread, but it's one of the first (and few) that kept coming up while I was googling for an answer.

    I ended up deriving my own combo box from QComboBox and overrode the paintEvent() function as shown below.
    This was done on QT 5.2.1

    Cpp Code:
    1. ///////////////////////////////////////////////////////////////////////////////////////////////////
    2. /// This class is a custom QComboBox which does NOT display the down arrow. The down arrow takes
    3. /// a lot of real estate when you're trying to make them narrow. So much real estate that you can't
    4. /// see short lines of text such as "CH 1" without the digit cut off. The only thing that this
    5. /// custom widget does is to override the paint function. The new paint function draws the combo
    6. /// box (using all style sheet info) without the down arrow.
    7. ///////////////////////////////////////////////////////////////////////////////////////////////////
    8. class tcNoArrowComboBox : public QComboBox
    9. {
    10. Q_OBJECT
    11. public:
    12. tcNoArrowComboBox (QWidget *parent) : QComboBox(parent) {}
    13. void paintEvent (QPaintEvent *ev);
    14. };
    15.  
    16. void tcNoArrowComboBox::paintEvent (QPaintEvent *ev)
    17. {
    18. QPainter p;
    19. p.begin (this);
    20. QStyleOptionComboBox opt;
    21. opt.initFrom (this);
    22. style()->drawPrimitive (QStyle::PE_PanelButtonBevel, &opt, &p, this);
    23. style()->drawPrimitive (QStyle::PE_PanelButtonCommand, &opt, &p, this);
    24. style()->drawItemText (&p, rect(), Qt::AlignCenter, palette(), isEnabled(), currentText());
    25. p.end();
    26. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jul 2018
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QcomboBox hide the drop down arrow

    Using styleSheet:

    QComboBox::down-arrow { image: none; }

Similar Threads

  1. QComboBox: remove drop Down Arrow
    By GuS in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2008, 05:05
  2. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 20:25

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.