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. How to define a property of type 'palette'?
Forum Updated to NodeBB v4.3 + New Features

How to define a property of type 'palette'?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 1.5k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    So, according to docs, palette is a basic type (and part of Qt Quick Controls): https://doc.qt.io/qt-5/qml-palette.html

    How do I create a property of that type?

    My attempt:

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    Item
    {
        property Palette dialogPalette: 
        {
            base: "#222222"
            alternateBase: "#333333"
        }
    }
    

    States that "Palette" is not a type.
    Ok, true enough, in the docs, the basic type is written with lowercase "palette". But QML can't seem to handle lowercase type names.

    Any ideas?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by sierdzio
      #2
      palette {
        base: "#222222"
        alternateBase: "#333333"
      }
      

      Or:

      palette.base: "#222222"
      palette.alternateBase: "#333333"
      

      So it works the same as font and anchors do.

      (Z(:^

      A 1 Reply Last reply
      1
      • sierdzioS sierdzio
        palette {
          base: "#222222"
          alternateBase: "#333333"
        }
        

        Or:

        palette.base: "#222222"
        palette.alternateBase: "#333333"
        

        So it works the same as font and anchors do.

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @sierdzio
        Interesting. Is that a non-visual component or a property?

        A 1 Reply Last reply
        0
        • A Asperamanca

          @sierdzio
          Interesting. Is that a non-visual component or a property?

          A Offline
          A Offline
          Asperamanca
          wrote on last edited by Asperamanca
          #4

          @Asperamanca
          Ah, I think you misunderstood. I don't want to define the values of a component's existing palette property. I want to define a new palette property, e.g. to provide an interface to an outside QML file using my component.

          Because if I write the code as you posted, I get "Invalid property name 'palette'"

          EDIT:
          What does work is (EDIT2: No it doesn't: alternateBase is a read-only property in this case)

              property SystemPalette palette 
              palette.base: "#222222"
              palette.alternateBase: "#333333"
          

          ...but I don't really understand the relation between "palette basic type" and "system palette basic type", except that the system palette gets it's colors from the QPalette defined with QApplication

          sierdzioS 1 Reply Last reply
          0
          • A Asperamanca

            @Asperamanca
            Ah, I think you misunderstood. I don't want to define the values of a component's existing palette property. I want to define a new palette property, e.g. to provide an interface to an outside QML file using my component.

            Because if I write the code as you posted, I get "Invalid property name 'palette'"

            EDIT:
            What does work is (EDIT2: No it doesn't: alternateBase is a read-only property in this case)

                property SystemPalette palette 
                palette.base: "#222222"
                palette.alternateBase: "#333333"
            

            ...but I don't really understand the relation between "palette basic type" and "system palette basic type", except that the system palette gets it's colors from the QPalette defined with QApplication

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @Asperamanca said in How to define a property of type 'palette'?:

            Ah, I think you misunderstood. I don't want to define the values of a component's existing palette property. I want to define a new palette property, e

            Ouch, you're right, I misunderstood :-( I don't know how to define it in a new component. Looking at the code, though, it seems to be "just" QPalette:

            Q_PROPERTY(QPalette palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged FINAL REVISION 3)
            

            (https://code.woboq.org/qt5/qtquickcontrols2/src/quicktemplates2/qquickcontrol_p.h.html#QQuickControl)

            And looking here: https://code.woboq.org/qt5/qtdeclarative/src/quick/util/qquicksystempalette.cpp.html it seems that the QML type is SystemPalette, like you have found.

            (Z(:^

            A 1 Reply Last reply
            0
            • sierdzioS sierdzio

              @Asperamanca said in How to define a property of type 'palette'?:

              Ah, I think you misunderstood. I don't want to define the values of a component's existing palette property. I want to define a new palette property, e

              Ouch, you're right, I misunderstood :-( I don't know how to define it in a new component. Looking at the code, though, it seems to be "just" QPalette:

              Q_PROPERTY(QPalette palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged FINAL REVISION 3)
              

              (https://code.woboq.org/qt5/qtquickcontrols2/src/quicktemplates2/qquickcontrol_p.h.html#QQuickControl)

              And looking here: https://code.woboq.org/qt5/qtdeclarative/src/quick/util/qquicksystempalette.cpp.html it seems that the QML type is SystemPalette, like you have found.

              A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #6

              @sierdzio
              Well, there does seem to be a separate "palette" type defined for Qt Quick Controls

              See https://doc.qt.io/qt-5/qml-palette.html
              Vs https://doc.qt.io/qt-5/qml-qtquick-systempalette.html

              For me, I want to pass a palette through my custom Component to the contained QML components.

              sierdzioS 1 Reply Last reply
              0
              • A Asperamanca

                @sierdzio
                Well, there does seem to be a separate "palette" type defined for Qt Quick Controls

                See https://doc.qt.io/qt-5/qml-palette.html
                Vs https://doc.qt.io/qt-5/qml-qtquick-systempalette.html

                For me, I want to pass a palette through my custom Component to the contained QML components.

                sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                @Asperamanca said in How to define a property of type 'palette'?:

                For me, I want to pass a palette through my custom Component to the contained QML components.

                Since it's a QObject, just to pass it through you can possibly use var or QtObject types. Ugly but might just work.

                (Z(:^

                1 Reply Last reply
                1
                • Mike Trahearn 0M Offline
                  Mike Trahearn 0M Offline
                  Mike Trahearn 0
                  wrote on last edited by
                  #8

                  Appreciating this is an old ticket, I have acquired some pertinent updates.

                  Unfortunately Qt decided that QQuickWindow's QPalette property was going to be "upgraded" to QQuickPalette type which is not public (and it doesn't look like they want to make it either). There is currently no way to pass a QPalette from C++ into an ApplicationWindow's (or any other QQuickControl's) palette property. You have to work around it by setting every single palette group property:

                  https://doc.qt.io/qt-6/qml-qtquick-palette.html

                  You may also find SystemPalette useful to some extent if you set a QPalette on your QGuiApplication.

                  However take care: the following color roles are missing from SystemPalette API (and the documentation):

                  brightText >> https://bugreports.qt.io/browse/QTBUG-67557
                  link >> https://bugreports.qt.io/browse/QTBUG-53189
                  linkVisited >> (as above)
                  toolTipBase >> reported
                  toolTipText >> reported

                  Other referenced JIRA tickets:

                  https://bugreports.qt.io/browse/QTBUG-104040
                  https://bugreports.qt.io/browse/QTBUG-95591
                  https://bugreports.qt.io/browse/QTBUG-91365

                  and also this posting:

                  https://lists.qt-project.org/pipermail/development/2020-August/040133.html

                  1 Reply Last reply
                  3

                  • Login

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