Qt Forum

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

    Qt Academy Launch in California!

    Clickable 'buttons' on each row custom painted with QAbstractItemDelegate

    General and Desktop
    4
    8
    5957
    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.
    • R
      ronM71 last edited by

      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 Reply Quote 0
      • G
        giesbert last edited by

        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 Reply Quote 0
        • R
          ronM71 last edited by

          I'll give it a look. thanks.

          1 Reply Last reply Reply Quote 0
          • R
            ronM71 last edited by

            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 Reply Quote 0
            • G
              giesbert last edited by

              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 Reply Quote 0
              • A
                andre last edited by

                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 Reply Quote 0
                • R
                  ronM71 last edited by

                  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 Reply Quote 0
                  • D
                    dscyw last edited by

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