Results 1 to 5 of 5

Thread: Item Delegate and Signal/Slot

  1. #1
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Item Delegate and Signal/Slot

    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???

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Item Delegate and Signal/Slot

    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Item Delegate and Signal/Slot

    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:
    Qt Code:
    1. RWDelegate *del = new RWDelegate( );
    2. view->setItemDelegate( del );
    3. connect( this->getFieldsList(), SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int) ), del, SLOT( insertText( QTreeWidgetItem *, int ) ) );
    To copy to clipboard, switch view to plain text mode 
    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

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Item Delegate and Signal/Slot

    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

  5. #5
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Item Delegate and Signal/Slot

    Thanks again for your suggestion. I attached a picture that should make it much clearer. 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!

Similar Threads

  1. Item Delegate Visibility
    By raneeshambat in forum Newbie
    Replies: 1
    Last Post: 18th September 2009, 20:41
  2. Replies: 5
    Last Post: 10th August 2009, 10:50
  3. Delegate for a certain item?
    By somebody in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2008, 22:55
  4. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.