[Qt-interest] Setting the background color of a tab

Jonas Gehring jonas.gehring at boolsoft.org
Thu Aug 4 12:35:45 CEST 2011


Implementing a custom QStyle would impose the same limitations as using
style sheets, wouldn't it? You're still unable to set a specific color
for the tab at index i.

- Jonas

On 08/04/2011 11:52 AM, Frank Hemer wrote:
> On Thursday 04 August 2011 11:45:27 Jonas Gehring wrote:
>> On 08/04/2011 11:41 AM, Stefan Löffler wrote:
>>> Wouldn't it be better to simply override initStyleOption in your
>>> subclass? Something like (not tested)
>>
>> Unfortunately, initStyleOption() is not virtual, so you can't override
>> it. I don't have a clue why this function is non-virtual for QTabBar and
>> many other widgets, since this would be an easy way to extend their
>> visual representation.
>>
>> - Jonas
> 
> Try with a QStyle:
> 
> class MyTabWidget::TabStyle
>    : public QCommonStyle
> {
> 
>  public:
>    TabStyle () {}
>    virtual ~TabStyle () {}
> 
>    void drawControl (ControlElement el,
>          const QStyleOption * opt,
>          QPainter * p,
>          const QWidget * w) const
>    {
>       if (el == QStyle::CE_TabBarTab) {
>          const QStyleOptionTab * t = static_cast <const QStyleOptionTab *> 
> (opt);
>          if (t) {
>             p->save ();
>             QStyleOptionTab tab (*t);
> 
>             if (t->state.testFlag (QStyle::State_Selected)) {
>                if (isPrivate) {
>                   tab.palette.setColor (QPalette::WindowText, QColor 
> (somecolor));
>                }
>                tab.palette.setBrush (QPalette::Window, QBrush (somebrush));
>             } else {
>                tab.palette.setColor (QPalette::WindowText, QColor 
> (somecolor));
>                tab.palette.setBrush (QPalette::Button, somebrush);
>             }
>             QApplication::style ()->drawControl (el, &tab, p, w);
>             p->restore ();
>          } else {
>             QApplication::style ()->drawControl (el, opt, p, w);
>          }
>       } else {
>          QApplication::style ()->drawControl (el, opt, p, w);
>       }
>    }
> };
> 
> Frank
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110804/8a84ddf6/attachment.bin 


More information about the Qt-interest-old mailing list