Results 1 to 7 of 7

Thread: QTreeWidget - itemAt(QMousePos): error if there is a header

  1. #1
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QTreeWidget - itemAt(QMousePos): error if there is a header

    Hi, I have a problem with QTreeWidget with function itemAt(QMousePos). If there is a header in tree widget then function returns next item. Is it a bug?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTreeWidget - itemAt(QMousePos): error if there is a header

    Post a minimal compilable code reproducing the problem

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget - itemAt(QMousePos): error if there is a header

    Quote Originally Posted by Phalanx View Post
    Hi, I have a problem with QTreeWidget with function itemAt(QMousePos). If there is a header in tree widget then function returns next item. Is it a bug?
    No, it's not a bug. The coordinates are in viewport space not the view space.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    Phalanx (15th April 2011)

  5. #4
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidget - itemAt(QMousePos): error if there is a header

    Thank you wysota

  6. #5
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidget - itemAt(QMousePos): error if there is a header

    I can not figured it out.

    I use it this way now, but it is not working with header:

    Qt Code:
    1. // without header works fine
    2. QMouseEvent *MousePos; // where the user clicked
    3. treeWidget->itemAt(MousePos->pos())
    4.  
    5. // with header, try to get global position but never returns item
    6. QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
    7. QPoint globalPos = ui->treeWidget->viewport()->mapToGlobal(mouseEvent->pos());
    8. QTreeWidgetItem *item = ui->treeWidget->itemAt(globalPos);
    To copy to clipboard, switch view to plain text mode 

    fuck, nothing works
    Last edited by Phalanx; 25th April 2011 at 15:03.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget - itemAt(QMousePos): error if there is a header

    Why are you trying to get a global position? You don't need a global position but position in the viewport's coordinate space.

    This should work:
    Qt Code:
    1. QPoint pos = ui->treeWidget->viewport()->mapFromParent(event->pos());
    To copy to clipboard, switch view to plain text mode 

    or something like that, depending on what is the receiver of the event.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidget - itemAt(QMousePos): error if there is a header

    Thank you, that's it It tooks me few hours of my life

Similar Threads

  1. Help with QTreeWidget header
    By jwieland in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2009, 13:36
  2. How to Add a Button in QTreeWidget Header?
    By ioannis in forum Qt Programming
    Replies: 1
    Last Post: 1st October 2008, 10:52
  3. QTreeWidget itemAt
    By maartenS in forum Newbie
    Replies: 4
    Last Post: 17th September 2008, 19:19
  4. Replies: 6
    Last Post: 15th September 2007, 22:14
  5. Two-row header for QTreeWidget
    By wetzel in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2006, 12:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.