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. Customizing labs components
QtWS25 Last Chance

Customizing labs components

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 998 Views
  • 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.
  • T Offline
    T Offline
    treaves
    wrote on last edited by
    #1

    I was reading over http://doc.qt.io/qt-5/qtlabscontrols-customize.html#customizing-itemdelegate for automizing an ItemDelegate. almost all of the code on the referenced page includes references to 'control'. For example:

    background: Rectangle {
        implicitWidth: 100
        implicitHeight: 40
        visible: control.pressed || control.highlighted
        color: control.pressed ? "#bdbebf" : "#eeeeee"
    }
    

    Where background is a property of ItemDelegate.

    But this code does not work. I get errors that 'ReferenceError: control is not defined'. I thought at first that perhaps 'control' was the id of the control containing this code, but, that doesn't seem to work either.

    When I change 'control' to be the id of the component, I do not get errors, but the code doesn't work. In this example, the background never changes, even when clicked (I have an onClick that logs to console, so I know it's getting clicked).

    So what is control in this context?

    Thanks.

    T 1 Reply Last reply
    0
    • T treaves

      I was reading over http://doc.qt.io/qt-5/qtlabscontrols-customize.html#customizing-itemdelegate for automizing an ItemDelegate. almost all of the code on the referenced page includes references to 'control'. For example:

      background: Rectangle {
          implicitWidth: 100
          implicitHeight: 40
          visible: control.pressed || control.highlighted
          color: control.pressed ? "#bdbebf" : "#eeeeee"
      }
      

      Where background is a property of ItemDelegate.

      But this code does not work. I get errors that 'ReferenceError: control is not defined'. I thought at first that perhaps 'control' was the id of the control containing this code, but, that doesn't seem to work either.

      When I change 'control' to be the id of the component, I do not get errors, but the code doesn't work. In this example, the background never changes, even when clicked (I have an onClick that logs to console, so I know it's getting clicked).

      So what is control in this context?

      Thanks.

      T Offline
      T Offline
      treaves
      wrote on last edited by treaves
      #2

      I've determined that 'control' is supposed to refer to the id of the containing control, in this case the ItemDelegate. So the color does get set while the element is pressed, but, not when it's not pressed. It this example, the color is set to '#eeeeee' while pressed, but is NOT '#dbdebf' while not pressed.

      jpnurmiJ 1 Reply Last reply
      0
      • T treaves

        I've determined that 'control' is supposed to refer to the id of the containing control, in this case the ItemDelegate. So the color does get set while the element is pressed, but, not when it's not pressed. It this example, the color is set to '#eeeeee' while pressed, but is NOT '#dbdebf' while not pressed.

        jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by
        #3

        Hi, notice the binding for the visible-property. The background is only visible when the delegate is either pressed or highlighted. You can remove the line if you want it to stay always visible.

        1 Reply Last reply
        1
        • T Offline
          T Offline
          treaves
          wrote on last edited by
          #4

          I had assumed that when the element was selected - in my case tapped on - that highlighted would equal true. But it doesn't.

          I understand your response, Asking slightly differently then, what property does get set that I can use in this background component that will be true when it's the selected list element?

          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