PDA

View Full Version : Item Delegate and Signal/Slot



LynneV
10th March 2010, 20:31
I have an ItemDelegate for a TreeView that contains multiple widgets and displays a different editor for each node type. I also have a docking window that contains a TreeWidget with a heirarchical list of text items. I want the user to be able to double-click on an item in the docking window and then insert the text into the active ItemDelegate editor widget (derived from QTextEdit). I am using the doubleClicked signal in the docking window's TreeWidget, and connecting it to a slot in the ItemDelegate without an issue. I get the double-clicked text in the corresponding Slot of the ItemDelegate. However, I can't figure out how to take that text and insert it into the correct widget inside the editor. The Slot doesn't have any information about the editor (if I use parent() it crashes) so I can't find out which edit field has focus to insert text. I tried emitting another signal from the ItemDelegate to a slot in the editor widget (I made the connection in CreateEditor), but it never gets caught. Any suggestions to try???

aamer4yu
11th March 2010, 05:40
How are you mapping the item from QTreeWidget in dock widget to the QTreeView ? I mean are you trying that when treewidget is clicked, the text of that item should get inserted in the editor of treeview? But editor for which row/col in the tree view ?
You could do one thing, you can pass the string in signal and set that data as the editor data.

Also if both treeview and treewidget has same data, why do you need 2 views to display ? Am not getting the overall idea of your gui.

LynneV
11th March 2010, 06:43
Thanks for replying! The TreeWidget that is the source for the text is in a dock widget. It is not the same TreeView that is showing the Item Delegate. The Item Delegate is editing text lines for a report writer. The dock widget is showing a heirarchical list of available tables and table fields for inserting into those report lines. I am currently connecting the itemdoubleclicked signal from the dock widget tree to the item delegate as in:


RWDelegate *del = new RWDelegate( );
view->setItemDelegate( del );
connect( this->getFieldsList(), SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int) ), del, SLOT( insertText( QTreeWidgetItem *, int ) ) );

I want to insert the text() from the itemDoubleClicked signal into the specific ItemDelegate QTextField that has focus. But I don't know how to get the signal to relay from the delegate to the editor widget and/or how to get the editor widget with focus in the delegate insertText slot() in order to insert it. Any suggestions are most welcome

aamer4yu
11th March 2010, 07:20
What have you applied the delegate to ? is it a QTreeView or a QTreeWidget ?
If it is a QTreeWidget, you can call treeWidget->editItem(item). The item you get in the slot, right ? Also you will need to set some function in the delegate which will use it to set value in setEditorData function.
Hope you get the idea

LynneV
11th March 2010, 15:16
Thanks again for your suggestion. I attached a picture that should make it much clearer.http://www.powervista.com/download_files/RWimage.jpg It is a QTreeView and I have re-implemented all the functions (createeditor, setmodeldata, paint, size hint and set geometry). There are several widgets in each editor at each node and 4 different editors based on line type. The problem is that the signal from the dock QTreeWidget carries that widget's WidgetItem - the slot function doesn't get called with a QModelIndex for the receiver, or any other data that lets me figure out which ModelIndex is the receiver. The Application current focus method gives me the dock widget's QTreeView (which it should, it just got a double-click mouse action). And I can't get the signal to relay to the editor, I suppose because it gets created 'on-demand'. I'm sure there's a brilliant way to do this... but I haven't found it yet!