[Interest] Widen down-arrow of QComboBox

Joshua Grauman jnfo-c at grauman.com
Mon Dec 30 01:34:48 CET 2013


Hello all,

I'm trying to get the down arrow of a QComboBox to be wider than the 
default. I've tried lots of different ideas and none are working as 
expected. I'm using the Fusion style and Qt5.2. If possible, I'd like to 
keep having the style draw everything and not have to redo all the 
painting myself.

The best I've come across is subclassing QProxyStyle and reimplementing 
subControlRect() for the ComboBoxArrow as follows. This almost works, but 
when the ComboBox is editable, then the lineEdit doesn't change size and 
overdraws the down arrow button (maybe a bug in the style?). I've tried 
playing with different features of the style and none that I've found are 
able to control this parameter.

QRect subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *option, QStyle::SubControl sc, const QWidget *widget) const
{
   if(cc == CC_ComboBox && sc == SC_ComboBoxArrow)
     return(QRect(widget->width()-widget->height(),0,widget->height(), widget->height()));
   return QProxyStyle::subControlRect(cc, option, sc, widget);
}

I also tried using a style sheet as follows, but this changes the image, 
but not the width of the down-arrow for some reason:
   QComboBox::down-arrow {width:60px; height:60px; image: url(./test.png);}

Thanks for any ideas!

Josh



More information about the Interest mailing list