Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with style sheets and custom properties
QtWS25 Last Chance

Problem with style sheets and custom properties

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giesbert
    wrote on last edited by
    #1

    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?

    Nokia Certified Qt Specialist.
    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        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...

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          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).

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

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

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              Voted.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved