[Qt-interest] Stylesheets: user-created widgets don't get styled

André Fillipe andref at syst.com.br
Sun Oct 25 22:44:17 CET 2009


Greetings!

I'm writing an app that uses style sheets and noticed a strange
behavior: Qt is not styling the widgets I write. A QFrame gets styled,
my SuperDuperFrame does not. I'm not reimplementing the paintEvent or
doing anything fancy. In fact, most of them are form-like panes that
extend QWidget or QFrame and were created in Designer. Even a trivial
widget like this doesn't get styled:

class CeciNestPasUnQWidget : public QWidget
{
    Q_OBJECT

public:

    CeciNestPasUnQWidget(QWidget* parent = NULL) : QWidget(parent)
    {}

    virtual ~CeciNestPasUnQWidget()
    {}
};

Since the documentation doesn't mention styling being limited to
bundled widgets, I decided to investigate. At first I thought that
either the widget nesting or the various other styling rules in my
style sheet were confusing Qt. I wrote a very simple test application
to verify this and found out that it wasn't the case.

I noticed that if I removed the Q_OBJECT macro from my class
declaration, the widget did get styled. "This is odd," I thought, and
went to check if QStylesheetStyle was processing the meta-objects
correctly, but QStyleSheetStyleSelector::nodeNameEquals correctly
identified my classes as extending QWidget.

Since there is an interaction between QStylesheetStyle and the default
style of the application, I tried each of "plastique", "cleanlooks",
"gtk", "windows", and (unnecessarily) "motif". The first three behaved
as I described, but "windows" applied the style to the widgets in some
cases and in others, not. I'm investigating this.

The problem occurs in this environment:

- Ubuntu 9.10 (development branch)
- Any of Qt SDK 4.5.2, Qt 4.6.0 TP1 and Qt 4.6.0 Beta 1
- gcc version 4.4.1
- It shouldn't matter, but who knows: all .h and .cpp files are strictly ASCII.

The test application is attached. I'm still trying to find the cause
here. If anyone has ever encountered this problem, please help!

Thank you so much,

--
André
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StylesheetTest.zip
Type: application/zip
Size: 9446 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091025/872fdf81/attachment.zip 


More information about the Qt-interest-old mailing list