[Interest] QSS/CSS styling a border on a combo removes styles from dropdown control

Nurmi J-P jpnurmi at digia.com
Wed Nov 27 13:15:26 CET 2013


On 27 Nov 2013, at 12:46, Philipp Kursawe <phil.kursawe at gmail.com> wrote:

> That's what I already did. I am using the second variant.
> 
> 
> On Wed, Nov 27, 2013 at 12:07 PM, Nurmi J-P <jpnurmi at digia.com> wrote:
> 
> On 27 Nov 2013, at 11:10, Philipp Kursawe <phil.kursawe at gmail.com> wrote:
> 
> > I wonder if that is a bug:
> > If I style a QComboBox's border with a "2px solid red" it looses its style on the dropdown arrow, which happened to be flat styled (on Windows) and then appears in 3D beveled style like old Win95. No more styles have been applied to this combo via css.
> >
> > Whats going on here?
> >
> > Is there a way to bring back the "default" style (reset a style) on the dropdown sub-control?
> >
> 
> Try using selectors [*] to avoid applying the border to all children of QComboBox.
> 
> These two have very different results:
> 
>     comboBox1->setStyleSheet("border: 2px solid red;”);
>     comboBox2->setStyleSheet("QComboBox { border: 2px solid red; }”);
> 
> [*] http://qt-project.org/doc/qt-5.1/qtwidgets/stylesheet-syntax.html#selector-types

Oh, I missed the “arrow” part. I thought the drop down was getting undesired style changes, which you can avoid by using selectors. Anyway, I’m afraid there’s no way to keep the native arrow whilst applying _stylesheets_ to the other parts of the combo box. Once you apply a stylesheet, you lose the native style.

What you could do instead is to customize individual primitives/subcontrols (perhaps SC_ComboBoxFrame?) using a proxy style. That way you can keep the native style for the other primitives/subcontrols (eg. SC_ComboBoxArrow).

http://doc-snapshot.qt-project.org/qt5-release/qproxystyle.html

--
J-P Nurmi




More information about the Interest mailing list