Problem with style sheets and custom properties



  • Hi,

    I have a complex style sheet for my application. We do many changes there, even depending on custom properties.

    so my style sheets looks like this:

    @
    QLineEdit
    {
    selection-background-color: rgb(51,102,211);
    selection-color: rgb(255,255,255);
    border: 1px solid rgb(138,138,138);
    background: rgb(255,255,255);
    color: rgb(0,0,0);
    padding-left: 1px; /* 3 px away from left border (pg 72) /
    padding-right: 2px;
    padding-bottom: 2px; /
    4 pixels from bottom border */
    padding-top: 0px;
    max-height: 14px;
    min-height: 14px;
    }
    QLineEdit[error="true"]
    {
    background: rgb(255,193,207);
    }
    @

    Then I have a custom QLineEdit derived class like this:

    @
    class CqLineEdit : public QLineEdit
    {
    Q_OBJECT
    Q_PROPERTY(bool error READ isError WRITE setError NOTIFY updateStyle)
    ...
    }

    void CqLineEdit::setError(bool bValue)
    {
    m_bError = bValue;
    emit updateStyle();
    }
    @

    What I would expect is that the visual representation of the line edit would switch, when I change the property error from true to false and vice versa (background color red or white). But the only possibility I found to solve this up to now is using internals of Qt:

    @
    #include <QtGui/private/qwidget_p.h>
    #include <QtGui/private/qstylesheetstyle_p.h>

    class QETWidget : public QWidget
    {
    public:
    void RepolishStyleSheet(bool bRecursive = true)
    {
    priv()->inheritStyle();
    update();
    }
    };

    void CqLineEdit::setError(bool bValue)
    {
    m_bError = bValue;
    QETWidget* pEtWidget = (QETWidget*)this;
    pEtWidget->RepolishStyleSheet();
    }
    @

    This works if the qwidget_p.h is included as QETWidget is a friend class of QWidget ;-( But I would prefer a solution using only the public API. Any ideas on how to solve that?



  • As far as I know the only way is to re-apply the stylesheet.



  • I stumbled over something in the "faq":http://developer.qt.nokia.com/faq/answer/how_can_my_stylesheet_account_for_custom_properties but from my perspective, this is not a nice solution ;-(

    Reaplying the style sheet is not an option, as the style sheet is about 3.500 lines and is applied at application level. I don't want to set the style sheet on app level for each property change in a widget. I will live with the unpolish/repolish solution as I found no other...



  • I know, there aren't any satisfying solutions. There should be definitly a possibility to at least manually repolish a single widget. A clean solution would be to automatically repolish the widget as soon as a bound property has changed (as this is what someone would expect when using properties with style sheets).



  • I created a "JIRA suggestion QTBUG-21762":https://bugreports.qt.nokia.com/browse/QTBUG-21762



  • Voted.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.