Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Customizing labs components

    QML and Qt Quick
    2
    4
    755
    Loading More Posts
    • 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
      treaves last edited by

      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 Reply Quote 0
      • T
        treaves @treaves last edited by 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.

        jpnurmi 1 Reply Last reply Reply Quote 0
        • jpnurmi
          jpnurmi @treaves last edited by

          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 Reply Quote 1
          • T
            treaves last edited by

            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 Reply Quote 0
            • First post
              Last post