Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create delegates that are always editable?
Forum Updated to NodeBB v4.3 + New Features

How to create delegates that are always editable?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 224 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.
  • P Offline
    P Offline
    peter.thompson
    wrote on last edited by
    #1

    I'm working with Qt's model/view framework. It's a fairly normal model and view, where each row can be thought of as an object, and each column is an attribute on that object. For some of the columns, I want to display something more than text. For example, there is a "Color" column where I want to display a widget that shows the current color and allows you to click on it to open up a color-selection dialog box.

    From what I understand, the best way to do this would be with a delegate. The delegate for the color column would load a custom editor widget. This custom editor widget would be a button (or some other type of clickable widget) that, when clicked on, would open up the color-selection dialog box.

    However, it looks like delegates only load up their editor widget when the edit trigger is triggered. This means I have to click on the cell once to "edit" it and load up the editor widget. Then I have to click on this editor widget to open up the dialog box. What I'm looking for is a way to have this editor widget always loaded up so that I can click on it directly at any time.

    My team has done this in the past using QAbstractItemView::setIndexWidget(), but I'm wondering if there is a more "proper" way to do this with delegates.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You don't need any intermediate widgets. When reimplementing createEditor, you can return a QColorDialog.

      You have an example in Python here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        You don't need any intermediate widgets. When reimplementing createEditor, you can return a QColorDialog.

        You have an example in Python here.

        P Offline
        P Offline
        peter.thompson
        wrote on last edited by
        #3

        @SGaist I think that approach may work for the color column, so thank you for explaining it.

        We also have a "Transparency" column, which is a little more complicated than the color column. I probably should have started with it as my example. The widget in the transparency column actually has two buttons: a cube and a downward arrow. Clicking on the cube just toggles between opaque and transparent. Clicking on the arrow opens up a little slider for fine control over the level of transparency. In addition, we'd like the buttons to respond when the user hovers over them, something to indicate that they are clickable.

        Transparency Widget

        This is where I'm getting the idea of a delegate that is always editable, so that the widget is always loaded. We really want it to be apparent to the user that this is a button that they can interact with. Would using QAbstractItemView::setIndexWidget() be the standard way to do that? Or should this still be done somehow with delegates?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          setIndexWidget should be used only for showing some static data in some cell. Not to fill views with widgets.
          You can still use a delegate for that transparency editor. It will need a bit more work though.
          The editorEvent method will help you with that.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply
          0
          • SGaistS SGaist

            setIndexWidget should be used only for showing some static data in some cell. Not to fill views with widgets.
            You can still use a delegate for that transparency editor. It will need a bit more work though.
            The editorEvent method will help you with that.

            P Offline
            P Offline
            peter.thompson
            wrote on last edited by
            #5

            @SGaist Thanks for your answer. I'll look into editorEvent().

            I found another answer online that mentions QAbstractItemView.openPersistentEditor(). Beyond performance considerations, would there be a strong reason not to use this method? (The lists I'm working with would have, at most, hundreds of items. Usually it's less than a hundred, so performance isn't the strongest consideration.)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It still means that you will have a hundred of widgets at least depending on how you implement your editor opened all the time. That still burns resources for not much benefit.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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