Qt Forum

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

    Qitemdelegate signal / slot

    General and Desktop
    2
    8
    2746
    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.
    • D
      DBGTMaster last edited by

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

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

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

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

            1 Reply Last reply Reply Quote 0
            • D
              DBGTMaster last edited by

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

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

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

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

                  1 Reply Last reply Reply Quote 0
                  • A
                    andre last edited by

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