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. How to use Enum as QProperty + StyleSheet?
Forum Updated to NodeBB v4.3 + New Features

How to use Enum as QProperty + StyleSheet?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 394 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rua3n
    wrote on last edited by
    #1

    How to use an Enum as QProperty and update it value using a stylesheet?

    class Gallery : public QScrollArea
    {
        Q_OBJECT
        Q_PROPERTY(int horizontalSpacing MEMBER horizontalSpacing) 
        Q_PROPERTY(Orientation orientation MEMBER Orientation WRITE setOrientation)
    
    public:
        int horizontalSpacing;
    
        enum Orientation { TOP, BOTTOM, LEFT, RIGHT };
        Orientation orientation;
        void setOrientation(Orientation orientation);
    };
    

    This is not compiling, the error:
    C7624: Type name 'Gallery::Orientation' cannot appear on the right side of a class member access expression

    My goal is to dynamically update the value using a stylesheet as:

    Gallery
    {
        qproperty-horizontalSpacing: 30;
        qproperty-orientation: top;
    }
    
    Christian EhrlicherC 1 Reply Last reply
    1
    • R Rua3n

      How to use an Enum as QProperty and update it value using a stylesheet?

      class Gallery : public QScrollArea
      {
          Q_OBJECT
          Q_PROPERTY(int horizontalSpacing MEMBER horizontalSpacing) 
          Q_PROPERTY(Orientation orientation MEMBER Orientation WRITE setOrientation)
      
      public:
          int horizontalSpacing;
      
          enum Orientation { TOP, BOTTOM, LEFT, RIGHT };
          Orientation orientation;
          void setOrientation(Orientation orientation);
      };
      

      This is not compiling, the error:
      C7624: Type name 'Gallery::Orientation' cannot appear on the right side of a class member access expression

      My goal is to dynamically update the value using a stylesheet as:

      Gallery
      {
          qproperty-horizontalSpacing: 30;
          qproperty-orientation: top;
      }
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Rua3n said in How to use Enum as QProperty + StyleSheet?:

      Q_PROPERTY(Orientation orientation MEMBER Orientation WRITE setOrientation)

      The member is wrong.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Rua3n said in How to use Enum as QProperty + StyleSheet?:

        Q_PROPERTY(Orientation orientation MEMBER Orientation WRITE setOrientation)

        The member is wrong.

        R Offline
        R Offline
        Rua3n
        wrote on last edited by Rua3n
        #3

        @Christian-Ehrlicher Now it compiled, but it's calling the setOrientation function with a "wrong" value

        Using:

        Gallery
        {
            qproperty-horizontalSpacing: 30;
            qproperty-orientation: "left";
        }
        

        the setOrientation function is not called.
        Using:

        Gallery
        {
            qproperty-horizontalSpacing: 30;
            qproperty-orientation: left;
        }
        

        The function is called but, the value of orientation is 19, what does this mean?

        void Gallery::setOrientation(Orientation orientation)
        {
        }
        
        D 1 Reply Last reply
        0
        • R Rua3n

          @Christian-Ehrlicher Now it compiled, but it's calling the setOrientation function with a "wrong" value

          Using:

          Gallery
          {
              qproperty-horizontalSpacing: 30;
              qproperty-orientation: "left";
          }
          

          the setOrientation function is not called.
          Using:

          Gallery
          {
              qproperty-horizontalSpacing: 30;
              qproperty-orientation: left;
          }
          

          The function is called but, the value of orientation is 19, what does this mean?

          void Gallery::setOrientation(Orientation orientation)
          {
          }
          
          D Offline
          D Offline
          Daniella
          wrote on last edited by
          #4

          @Rua3n i think you are missing Q_ENUM(orientation)

          R 1 Reply Last reply
          0
          • D Daniella

            @Rua3n i think you are missing Q_ENUM(orientation)

            R Offline
            R Offline
            Rua3n
            wrote on last edited by
            #5

            @Daniella I added Q_ENUM(Orientation) but it still 19

            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