Results 1 to 4 of 4

Thread: In QTreeView (and list view) signal when item is double clicked.

  1. #1
    Join Date
    Feb 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default In QTreeView (and list view) signal when item is double clicked.

    Hi there,

    I have a qtreeview (with a model) - Now I wish to execute some code (a slot) when an item in the tree view is double clicked. How can I do this? I'd prefer not having to derive from this treeview - as I'd like keep using the qt designer to design the interface.... Is this possible?

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: In QTreeView (and list view) signal when item is double clicked.


  3. #3
    Join Date
    Feb 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: In QTreeView (and list view) signal when item is double clicked.

    ok.... Strange I missed it ><

    However how do I use this? I tried doing something like:
    Qt Code:
    1. void MainInterface::DoubleClickInputTree(const QModelIndex& index) {
    2. QStandardItem * t = reinterpret_cast<QStandardItem *>(index.internalPointer());
    3. auto f(t->font());
    4. f.setBold(true);
    5. t->setFont(f);
    6. }
    To copy to clipboard, switch view to plain text mode 
    So on double clicking an item it ought to be "bolded" - however this doesn't seem to work???? - How do I get the item corresponding to the qmodelindex?

    EDIT:Nvm lol.. just after posting this I remembered reading "itemfromindex" somewhere so that helped me finding the correct function (auto t(model.itemFromIndex(index))

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: In QTreeView (and list view) signal when item is double clicked.

    If you want an item based approach, then use QTreeWidget. There you can use QTreeWidget::itemDoubleClicked() which delivers the item directly to the slot.
    If you are using a model, than you have to go via a custom delegate.

Similar Threads

  1. Replies: 1
    Last Post: 30th September 2011, 19:06
  2. double clicked on an item QTreeWidget
    By milli in forum Newbie
    Replies: 3
    Last Post: 7th May 2011, 21:49
  3. Getting the Id of a double clicked item
    By thefatladysingsopera in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2011, 14:18
  4. QTreeView clicked signal coordinates
    By michalk in forum Newbie
    Replies: 3
    Last Post: 1st February 2011, 13:21
  5. Replies: 0
    Last Post: 26th August 2010, 16:25

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.