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. Access colors of a QPalette property
Forum Updated to NodeBB v4.3 + New Features

Access colors of a QPalette property

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 298 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I have a C++ class which provides a QPalette as a property:

    Q_PROPERTY(QPalette activePalette READ getActivePalette NOTIFY notifyActivePaletteChanged)
    

    This class is registered in QML and can be called like so:

    Text
     {
        color: style.activePalette.windowText
        text: "Some text"
    }
    

    However, when I use style.activePalette.windowText, I get "Cannot read property 'windowText' of undefined"

    My understanding was that a QPalette on the C++ side becomes a palette QML type on the QML side, and for this 'windowText' is defined as "palette.windowText : color - A general foreground color."

    Any suggestions what goes wrong here?

    A 1 Reply Last reply
    0
    • A Asperamanca

      I have a C++ class which provides a QPalette as a property:

      Q_PROPERTY(QPalette activePalette READ getActivePalette NOTIFY notifyActivePaletteChanged)
      

      This class is registered in QML and can be called like so:

      Text
       {
          color: style.activePalette.windowText
          text: "Some text"
      }
      

      However, when I use style.activePalette.windowText, I get "Cannot read property 'windowText' of undefined"

      My understanding was that a QPalette on the C++ side becomes a palette QML type on the QML side, and for this 'windowText' is defined as "palette.windowText : color - A general foreground color."

      Any suggestions what goes wrong here?

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

      For anyone with the same issue: The cause here seems to be name shadowing. See https://forum.qt.io/topic/74969/qml-how-to-access-context-property-if-its-name-is-shadowed-by-a-component-local-property

      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