ariya.io About Collections Archives

Arrow in Plastique QComboBox

1 min read

If you try to find the dimension and position of the combobox arrow button, one of your chance is by using subControlRect of the style in use. Unfortunately, this can not work in Plastique style because this style does not return a correct QRect associated with the arrow’s geometry, as evidence from the source code:

case CC_ComboBox:
        switch (subControl) {
        case SC_ComboBoxArrow:
            rect = option->rect;
            break;

It simply gives back option->rect which is likely the widget’s own rect(). Your program might believe that the arrow occupies the whole combobox.

Fortunately, thanks to the Trolls, this problem is gone with the upcoming Qt 4.1.

But just in case you still want to work with Qt 4.0 (and 4.0.1), then you have to implement hackish fix like this:

QRect arrowRect = style()->subControlRect(QStyle::CC_ComboBox, 
        &opt;, QStyle::SC_ComboBoxArrow, this);
    if( arrowRect == opt.rect )
    {
        // workaround for broken subControlRect
        int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
        arrowRect = QRect(width()-16-fw, height()-2*fw);
    }
Related posts:

♡ this article? Explore more, check the archives, or follow me Twitter.

Share this on Twitter Facebook Google+

comments powered by Disqus