PDA

View Full Version : QcomboBox hide the drop down arrow



Mrdata
23rd October 2009, 22:54
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.

RSX
24th October 2009, 14:21
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.

Mrdata
24th October 2009, 19:00
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?

squidge
24th October 2009, 22:48
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.

helius
24th January 2011, 10:46
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 :D

Judge Gazza
24th March 2016, 21:13
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


///////////////////////////////////////////////////////////////////////////////////////////////////
/// This class is a custom QComboBox which does NOT display the down arrow. The down arrow takes
/// a lot of real estate when you're trying to make them narrow. So much real estate that you can't
/// see short lines of text such as "CH 1" without the digit cut off. The only thing that this
/// custom widget does is to override the paint function. The new paint function draws the combo
/// box (using all style sheet info) without the down arrow.
///////////////////////////////////////////////////////////////////////////////////////////////////
class tcNoArrowComboBox : public QComboBox
{
Q_OBJECT
public:
tcNoArrowComboBox (QWidget *parent) : QComboBox(parent) {}
void paintEvent (QPaintEvent *ev);
};

void tcNoArrowComboBox::paintEvent (QPaintEvent *ev)
{
QPainter p;
p.begin (this);
QStyleOptionComboBox opt;
opt.initFrom (this);
style()->drawPrimitive (QStyle::PE_PanelButtonBevel, &opt, &p, this);
style()->drawPrimitive (QStyle::PE_PanelButtonCommand, &opt, &p, this);
style()->drawItemText (&p, rect(), Qt::AlignCenter, palette(), isEnabled(), currentText());
p.end();
}

ForestDweller2
5th October 2018, 03:05
Using styleSheet:

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