Results 1 to 7 of 7

Thread: [SOLVED]QTreeWidget doesn't want to be edited

  1. #1
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question [SOLVED]QTreeWidget doesn't want to be edited

    Hey,

    I'm using Qt Creator to develop my app, and have a dialog containing a QTreeWidget. I populate it by querying a local database for record names. I can give the code for populating it, but I'm pretty sure I don't set any properties of the TreeWidget from there. Suffice it to say that I have Parents and Children being populated.

    I would like to allow my users to change parent names, but I can't get the Tree to accept a double click as an edit. Instead it treats double click as "Expand Children". I have the following call in the constructor of the dialog

    ui.flightSearchTree->setEditTriggers(QAbstractItemView::DoubleClicked) ;

    but to no avail.

    Any help is appreciated.:confused::confused:
    Last edited by grabalon; 27th July 2010 at 23:43. Reason: Solved the problem, so renamed the title

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QTreeWidget doesn't want to be edited

    Quote Originally Posted by grabalon View Post
    I'm pretty sure I don't set any properties of the TreeWidget from there.
    That's what you need to do. By default a QTreeWidgetItem is not editable (docs) so you need to set the flag:
    Qt Code:
    1. item->setFlags(item->flags() | Qt::ItemIsEditable);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to norobro for this useful post:

    grabalon (27th July 2010)

  4. #3
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget doesn't want to be edited

    That did it, thanks.

    As a followup, as best I can tell, the QTreeWidgetItem doesn't emit any signals, where would I connect to handle pushing the new name back into the database?

  5. #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: QTreeWidget doesn't want to be edited

    Cant you use a QTreeView with a proper model? That will simplify things a lot.

  6. #5
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget doesn't want to be edited

    Quote Originally Posted by Lykurg View Post
    That will simplify things a lot.
    Perhaps, but the conversion process at this point is not simple.

  7. #6
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QTreeWidget doesn't want to be edited

    Quote Originally Posted by grabalon View Post
    where would I connect to handle pushing the new name back into the database?
    Maybe in a custom delegate? By reimplementing setModelData() to update your DB.

  8. #7
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget doesn't want to be edited

    Posted for benefit of future readers:

    QTreeWidget::itemChanged(QTreeWidgetItem*, int)
    This signal solved my problems, but be sure to disconnect it if repopulating the QTreeWidget or you get some hyper signal emissions.

Similar Threads

  1. Replies: 5
    Last Post: 26th October 2014, 12:56
  2. Custom controls when QTreeWidgetItem edited.
    By kubas in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2009, 10:27
  3. QSpinbox can not be edited through keyboard on Linux
    By sanjayshelke in forum Qt Programming
    Replies: 0
    Last Post: 28th May 2008, 09:21
  4. QTreeWidget - Edited Rows
    By Preeteesh in forum Qt Programming
    Replies: 5
    Last Post: 18th June 2007, 16:44
  5. How to know when field is edited within QTableView
    By dkite in forum Qt Programming
    Replies: 3
    Last Post: 1st January 2007, 18:51

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.