Results 1 to 6 of 6

Thread: How to activate delegated item in qtreeview by custom shotcut.

  1. #1
    Join Date
    Jun 2006
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to activate delegated item in qtreeview by custom shotcut.

    Have anybody any ideas for realising custom edit key(not system F2) for editing item in qtreeview.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to activate delegated item in qtreeview by custom shotcut.

    Well, if you subclcass the treeview and override its keyPressEvent, the you could start editing the selected item when you press the desired key by calling QTreeView::edit(const QModelIndex&).
    You can get the selected index from the selection model.

  3. #3
    Join Date
    Jun 2006
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to activate delegated item in qtreeview by custom shotcut.

    If I have pushbutton, and want add action edit treeitem for it. Even F2 shotcut does not work:-(

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to activate delegated item in qtreeview by custom shotcut.

    So connect to button's signal, pick the current item and start editing? For example:
    Qt Code:
    1. connect(button, SIGNAL(clicked()), this, SLOT(editTreeItem()));
    2.  
    3. void Window::editTreeItem()
    4. {
    5. QModelIndex index = treeView->currentIndex();
    6. if (index.isValid())
    7. treeView->edit(index);
    8. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    visor_ua (6th December 2007)

  6. #5
    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 activate delegated item in qtreeview by custom shotcut.

    So you want to activate editing upon clicking the button or pressing the F2 key or both?

    The most straightforward way is to connect the clicked() signal of the button to a custom slot in the view (or some other class), get the current index and call edit() on it. The shortcut cat be assigned to the pushbutton by using the shortcut property.

  7. #6
    Join Date
    Jun 2006
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to activate delegated item in qtreeview by custom shotcut.

    Yes, this solution really what i need.
    Thanks

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.