Results 1 to 6 of 6

Thread: How to detect theright clicked item when using customContextMenuRequested signal

  1. #1
    Join Date
    May 2009
    Posts
    83

    Default How to detect theright clicked item when using customContextMenuRequested signal

    hello all
    quick question
    im using in Treewidget the customContextMenuRequested signal and using using popup with qmenu
    How can I get the item pointer / object / reference that just bean right clicked before the pop up executed
    I need to make some validation on the item

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

    Default Re: How to detect theright clicked item when using customContextMenuRequested signal

    QTreeWidget::itemAt() returns a pointer to an item in a specific point relative to the widget's top-left corner. Remember the widget is probably the view's viewport and not the view itself.
    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.


  3. #3
    Join Date
    May 2009
    Posts
    83

    Default Re: How to detect theright clicked item when using customContextMenuRequested signal

    one problem remains when i right click not on tree node i still trigger the customContextMenuRequested SLOT function , how can i check there is its QTreeWidgetItem object?

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

    Default Re: How to detect theright clicked item when using customContextMenuRequested signal

    I don't understand. If you click outside any item then the returned pointer will be null.
    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.


  5. #5
    Join Date
    May 2009
    Posts
    83

    Default Re: How to detect theright clicked item when using customContextMenuRequested signal

    found i think the answer
    QModelIndex index = this->indexAt(pos);
    then in the code..
    if(index.isValid()) .....

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

    Default Re: How to detect theright clicked item when using customContextMenuRequested signal

    You're using item based approach, so:
    Qt Code:
    1. QTreeWidgetItem *item = indexAt(pos);
    2. if(item) {
    3. // item is valid
    4. }
    To copy to clipboard, switch view to plain text mode 
    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.


Similar Threads

  1. Replies: 1
    Last Post: 16th December 2009, 02:48
  2. getting clicked item from listview
    By addu in forum Qt Programming
    Replies: 6
    Last Post: 14th May 2009, 10:33
  3. signal mapping on pushbutton signal clicked
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 07:54
  4. Getting item from QTableView when clicked on
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 11:58
  5. Replies: 17
    Last Post: 31st March 2006, 05:57

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.