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. Clickable 'buttons' on each row custom painted with QAbstractItemDelegate
Forum Updated to NodeBB v4.3 + New Features

Clickable 'buttons' on each row custom painted with QAbstractItemDelegate

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 6.4k 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.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    I'd like to draw 'clickable' icons (or buttons) on each row of a QListView I'm using my own custom "QAbstractItemDelegate" derived class to paint. Those buttons may change with the custom status of the row (i have access to the underlying data structure during painting).

    What's the best way to approach this?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      use a QStyledItemDelegate and use the style to draw the button
      "QStyle::drawControl":http://doc.qt.nokia.com/latest/qstyle.html#drawControl (QStyle::CE_PushButton, ...)

      You then have to react to the mouse clicks (which might need a subclass of the view) and can handle the clicks there.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ronM71
        wrote on last edited by
        #3

        I'll give it a look. thanks.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          ronM71
          wrote on last edited by
          #4

          So, there's no way to instantiate "live" controls in an item row? you have to "statically draw" them and handle every single mouse event for them, drawing them differently by updating flags in the row?

          My requirements are a row of 2 to 5 buttons (clickable images, really), for each row, with tooltips and a "mouse on" image that'sa slightly highlighted. I can do it myself I guess, but for instance, I don't receive a "enter"/"leave" mouse events in my itemDelegate::editorEvent. I only get clicks, and I don't even get mouse move unless i click it first.

          Any advice?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            you cpould also use real widgets by using "QAbstractItemView::setIndexWidget":http://doc.qt.nokia.com/latest/qabstractitemview.html#setIndexWidget
            Or you subclass the view :-(

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Or, if the licence of your application permits, look into KDE's code base and study or copy "goya" (KWidgetItemDelegate).

              Widgets in item views are always a bit of a problem, that was never solved in a satisfying way, if you ask me. In this respect, QML may be the better alternative. If platform consistency isn't your main goal, you might look into using a QDeclarativeView instead of a QListView and use QML-rendered items in your list. That will allow all the interaction, highlighting, etc. you need. However, getting to look platform conformant is harder (though there are recent "labs" projects that should take you a long way).

              1 Reply Last reply
              0
              • R Offline
                R Offline
                ronM71
                wrote on last edited by
                #7

                That sounds great! If I can have my own "row widget" class to

                Handle the creation/destruction of sub-widgets (buttons controls etc)

                Paint everything that's not sub-control (my own custom paint, just like I do now with my delegate)

                Process mouse events

                my problem is solved!

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dscyw
                  wrote on last edited by
                  #8

                  [quote author="ronM71" date="1301501984"]That sounds great! If I can have my own "row widget" class to

                  Handle the creation/destruction of sub-widgets (buttons controls etc)

                  Paint everything that's not sub-control (my own custom paint, just like I do now with my delegate)

                  Process mouse events

                  my problem is solved! [/quote]

                  Can you paste a code snippet for me?Thx.

                  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