Qt World Summit: Register Today!

QT paintEvent with custom widget

  • I have one custom widget and in custome widget we have many widget included mean label,lineedit
    etc. In custom widget we have applied stylesheet through paintEvent. but i want some of the
    widgets inside the custome widget should not use the stylesheet based on paintEvent
    so how to remove (not to apply stylesheet) that widget from paintEvent method ?


  • I'm assuming you're using traditional Qt (e.g. not QML or something).

    I'm not entirely sure by what you mean by "applied stylesheet through paintEvent", but perhaps I can suggest that you use a more specific CSS selector when setting the style.

    For example:

    QPushButton,QLabel { background: green; }

    .. will only style the QPushButton and QLabel objects


    #myText { color: green; }

    .. will only style the color of objects with a QObject::objectName() of "myText".


    .QWidget { background: red; }

    .. will only style objects of class QWidget but not sub-classes of QWidget

    Check out http://doc.qt.nokia.com/latest/stylesheet-syntax.html#selector-types for more info.

    Also, something I haven't seen documented, but is clearly in the code is that a property can be set to "native" (e.g. "border: native") to basically say that you want that property styled natively as if no stylesheet had been set.

    Apologies if I'm not understanding the question.

    [EDIT: code formatting, please wrap in @-tags, Volker]

Log in to reply