[Interest] Changing QSpinEdit color

André Somers andre at familiesomers.nl
Wed Jun 6 13:20:51 CEST 2012


Op 6-6-2012 11:07, A.Dmitrovsky schreef:
> here i found where is behaviour André is talking about documented:
>
> http://qt-project.org/doc/qt-4.8/stylesheet.html:
> When a style sheet is active, the QStyle returned by QWidget::style() is a wrapper "style sheet" style, not the platform-specific style. The wrapper style ensures that any active style sheet is respected and otherwise forwards the drawing operations to the underlying, platform-specific style (e.g., QWindowsXPStyle on Windows XP).
Clearer, perhaps, is this section from QWidget::setPalette:

    The current style, which is used to render the content of all
    standard Qt widgets, is free to choose colors and brushes from the
    widget palette, or in some cases, to ignore the palette (partially,
    or completely). In particular, certain styles like GTK style, Mac
    style, Windows XP, and Vista style, depend on third party APIs to
    render the content of widgets, and these styles typically do not
    follow the palette. Because of this, assigning roles to a widget's
    palette is not guaranteed to change the appearance of the widget.
    Instead, you may choose to apply a styleSheet. You can refer to our
    Knowledge Base article here for more information.

I think that quite clearly says what I also said: setPalette cannot be 
relied on, and is thus effectively useless. Pitty is: style sheet 
support is incomplete (no API for custom widgets), so in some cases 
(mainly if you use your own widgets), you're basically screwed. You 
cannot rely on the palette to work properly, but you cannot use style 
sheets either.

André

>
>
> 06.06.2012, 12:34, "André Somers"<andre at familiesomers.nl>:
>> Op 5-6-2012 20:47, "Alexander Carôt" schreef:
>>
>>>   Hi all,
>>>
>>>   I have a question in context with QSpinEdit:
>>>
>>>   On a Mac this call successfully changes the color of the spinEdit:
>>>
>>>   spin->setAutoFillBackground(true);
>>>   spin->setPalette( *greenFgPalette );
>>>
>>>   On Win, however, this call seems to be ignored - the spinEdit remains white. Can anyone tell me how to make it work under Win ?
>>>
>>>   Thanks in advance,
>>>   best
>>>
>>>   Alex
>> Styles are free to ignore the set palette, and some styles, especially
>> those using native rendering like on windows, do in fact ignore the
>> palette. However, all styles will obey the style sheet. So, instead of
>> the palette, use a style sheet.
>>
>> spin->setStyleSheet("QSpinBox {background-color: rgb(0, 255, 0);}");
>>
>> That should work on both platforms.
>>
>> André
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120606/e00688e7/attachment.html>


More information about the Interest mailing list