Results 1 to 3 of 3

Thread: Q_ENUMS and Qt Style Sheet

  1. #1
    Join Date
    Sep 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Q_ENUMS and Qt Style Sheet

    Well, strange things in QT happens when I try to load stylesheet, located in separate file

    I have a class looks like following:

    AClass.h:

    Qt Code:
    1. class AClass : public QFrame
    2. {
    3. Q_OBJECT
    4. Q_ENUMS(State)
    5. Q_PROPERTY(State status READ getStatus WRITE setStatus)
    6. Q_PROPERTY(int status_int READ getStatus_int WRITE setStatus_int)
    7. public:
    8. enum State {Ok,Wrong,Unknown};
    9. State getStatus() const {return m_status;}
    10. void setStatus(State status) {m_status=status;}
    11. int getStatus_int() const {return m_status_int;}
    12. void setStatus_int(int status) {m_status_int=status;}
    13. ...
    14. private:
    15. State m_status;
    16. int m_status_int;
    17. ...
    18. };
    To copy to clipboard, switch view to plain text mode 

    AClass.cpp:

    Qt Code:
    1. AClass::AClass(QWidget *parent) :
    2. QFrame(parent),
    3. m_status(Ok),
    4. m_status_int(0)
    5. {
    6. }
    7. ...
    To copy to clipboard, switch view to plain text mode 

    Lines in .css file:

    #AClass[status="Ok"] {background-color: lime;} //////////// DO NOT WORK
    #AClass[status_int="0"] {{background-color: lime;} /////////// EVERYTHING OK!

    Well, in Qt documentation written:
    "If the property references an enum declared with Q_ENUMS,
    you should reference its constants by name, i.e., not their numeric value."
    It seems to me it does not work at all...
    Possibly I'm too stupid to understand Q_ENUMS macros...
    Please! Help me anybody)

  2. #2
    Join Date
    Oct 2015
    Posts
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Q_ENUMS and Qt Style Sheet

    Hey I know I am about 3 years to late but did you ever figure this one out? I am currently having the same problem.

  3. #3
    Join Date
    Mar 2019
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Q_ENUMS and Qt Style Sheet

    Today I had similar problem, maybe someone is still looking for solution.
    That's what I've made:

    MyPushButton.h:

    Qt Code:
    1. class MyPushButton : public QPushButton
    2. {
    3. Q_OBJECT
    4.  
    5. Q_PROPERTY(QString style MEMBER _styleStr)
    6.  
    7. public:
    8. enum Style
    9. {
    10. StyleNormal = 1,
    11. StyleOk,
    12. StyleWarning,
    13. StyleRed,
    14. };
    15.  
    16. Q_ENUM(Style)
    17.  
    18. explicit MyPushButton(QWidget *parent = nullptr);
    19.  
    20. Style style() const;
    21. void setStyle(const Style &style);
    22.  
    23. private:
    24. Style _style;
    25. QString _styleStr;
    26. };
    To copy to clipboard, switch view to plain text mode 

    MyPushButton.cpp:

    Qt Code:
    1. ...
    2. MyPushButton::Style MyPushButton::style() const
    3. {
    4. return _style;
    5. }
    6.  
    7. void MyPushButton::setStyle(const Style &style)
    8. {
    9. switch (style)
    10. {
    11. case StyleNormal: _styleStr = "StyleNormal"; break;
    12. case StyleOk: _styleStr = "StyleOk"; break;
    13. case StyleWarning: _styleStr = "StyleWarning"; break;
    14. case StyleRed: _styleStr = "StyleRed"; break;
    15. }
    16.  
    17. _style = style;
    18. }
    19. ...
    To copy to clipboard, switch view to plain text mode 

    styles.css:
    Qt Code:
    1. ...
    2. MyPushButton[style="StyleRed"]
    3. {
    4. background-color: #ff0000;
    5. ...
    6. }
    7. ...
    To copy to clipboard, switch view to plain text mode 

    It works very well.

Similar Threads

  1. Problems with Gradient style used through Style sheet on ARM platform
    By puneet.narsapur in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th January 2010, 13:48
  2. Q_ENUMS on C-style global enums
    By luf in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2008, 20:11
  3. Style Sheet speed
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2008, 19:40
  4. Style Sheet on QWizard
    By desch in forum Qt Programming
    Replies: 2
    Last Post: 6th December 2007, 18:12
  5. How to use style sheet
    By safknw in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2006, 14:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.