PDA

View Full Version : How to activate delegated item in qtreeview by custom shotcut.



visor_ua
5th December 2007, 17:50
Have anybody any ideas for realising custom edit key(not system F2) for editing item in qtreeview.

marcel
5th December 2007, 18:05
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.

visor_ua
6th December 2007, 11:51
If I have pushbutton, and want add action edit treeitem for it. Even F2 shotcut does not work:-(

jpn
6th December 2007, 12:02
So connect to button's signal, pick the current item and start editing? For example:


connect(button, SIGNAL(clicked()), this, SLOT(editTreeItem()));

void Window::editTreeItem()
{
QModelIndex index = treeView->currentIndex();
if (index.isValid())
treeView->edit(index);
}

wysota
6th December 2007, 12:02
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.

visor_ua
6th December 2007, 14:43
Yes, this solution really what i need.
Thanks