Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-51236

Q_PROPERTY is not updated with values from stylesheet when a widget changed pseudo state

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.5.1
    • Widgets: Style Sheets
    • None
    • Windows 7, C++, VS2010

    Description

      I subclassed a QLineEdit and added an action.
      The action has an icon which is set in the stylesheet via qproperty-action_icon. The stylesheet defines also a style for the read-only pseudo state.
      Toggling read-only with setReadOnly( bool ) toggles the background color but not the action icon.

      class QMyLineEdit : public QLineEdit
      {
          Q_OBJECT
          Q_PROPERTY( QString action_icon READ GetIcon WRITE SetIcon )
      
      public:
          explicit QMyLineEdit( QWidget* parent )
              : m_pAction( nullptr )
          {
              m_pAction = new QAction( this );
              connect( m_pAction, &QAction::triggered, this, &QMyLineEdit::MyAction );
              addAction( m_pAction, QLineEdit::TrailingPosition );
          }
      
      private:
          QAction* m_pAction;
          QString  m_strIcon;
      
          const QString& GetIcon() const
          {
              return m_strClearIcon;
          }
          
          void SetIcon( const QString& strIcon )
          {
              m_strIcon = strIcon;
              QIcon Icon( m_strIcon );
              m_pAction->setIcon( Icon );
          }
          
          void MyAction(){ /* ... */ } 
      };
      
      // Stylesheet
      .QMyLineEdit {
          qproperty-action_icon: url(:/Widgets/action.png);
      }
      
      .QMyLineEdit:read-only {
          background-color: green;
          qproperty-action_icon: url(:/Widgets/action_readonly.png);
      }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Unassigned Unassigned
              JKlein Jasper
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes