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. Qitemdelegate signal / slot

Qitemdelegate signal / slot

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.2k 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.
  • D Offline
    D Offline
    DBGTMaster
    wrote on last edited by
    #1

    Hello,

    i have a qitemdelegate on a qtreeview. When the user moves with the cources over a position in a qitemdelegate, i will open a popup window.

    How can i check the position in a qitemdelegate??

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

      You should reimplement virtual bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) in your delegate. It will get called with mouse events I think. If not, you might need to enable mouse tracking on the widget.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DBGTMaster
        wrote on last edited by
        #3

        Thnaks, it works!

        How can i get in the editorEvent the mouse Position relative to the delegate field?

        option.rect.x() returns the position relative to my monitor...

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

          You might be able to use QWidget::mapFromGlobal for that task.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DBGTMaster
            wrote on last edited by
            #5

            Ok, i need the x & y coordinate relative to the view..
            In the editorEvent, how can i get the QTreeView Object?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DBGTMaster
              wrote on last edited by
              #6

              My situation:

              I have a Delegate, in which i overloaded the paint method, and the editorEvent.

              In the paint method, i draw some points, and i get the position of the x,y with the following code:
              @ int x = option.rect.x();
              int y = option.rect.y();@

              When the mouse is over the point, i will execute some actions, so the painted point must have in the editorEvent the same coordinates as in the point method.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DBGTMaster
                wrote on last edited by
                #7

                @ QMouseEvent mouseEvent = static_cast<QMouseEvent>(event);
                qDebug() << mouseEvent->x() << mouseEvent->y();@

                returns in the editorEvent the correct positions, thanks :)!

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

                  Please just edit your previous post instead of posting three messages in a row...

                  What I'd do, is make your delegates constructor so that it takes a pointer to a QAbstractItemView. That way, you always have a pointer to the widget the delegate is used for. This is not a hack, as the documentation for delegates already warns about re-using the same delegate for multiple views. So, they are already "bound" to a specific view anyway.

                  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