Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Accessing Material colors in QML C++ extension
Forum Updated to NodeBB v4.3 + New Features

Accessing Material colors in QML C++ extension

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 1.3k Views 2 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
    ruisebastiao
    wrote on last edited by A Former User
    #1

    I have the following code in a C++ extension :

    
    class User : public QQuickItem
    {
        Q_OBJECT
        Q_DISABLE_COPY(User)
    
    
        Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged)
        Q_PROPERTY(int temperature READ temperature WRITE setTemperature NOTIFY temperatureChanged)
        Q_PROPERTY(QColor primaryColor READ primaryColor WRITE setPrimaryColor NOTIFY primaryColorChanged)
    
        QString m_name;
        QString m_userName;
    
        int m_temperature;
    
        QColor m_primaryColor= Material.color(Material.Indigo);
    
    

    How can i acess to the Material functions / Color enumerations?

    Thanks,

    Rui Sebastiao

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by jeremy_k
      #2

      The enum is defined in a private header (qquickmaterialstyle_p.h) that isn't shipped with The Qt Company's binary packages. Without modifying a build, grabbing the enum at compile time purely from C++ doesn't appear to be possible.

      Some options are to parse the output of 'qmlplugindump -nonrelocatable QtQuick.Controls.Material 2.0', or use a piece of QML to store the enum values in properties of a QML object for retrieval in C++.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      1
      • jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by
        #3

        Assuming that User is registered as a QML type, the natural way would be to pass the color from QML:

        User {
            primaryColor: Material.color(Material.Indigo)
        }
        

        This is essentially what the Material style itself does.

        1 Reply Last reply
        2

        • Login

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