Results 1 to 4 of 4

Thread: Should I implement an own version of QItemDelegate for QTreeView?

  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Should I implement an own version of QItemDelegate for QTreeView?

    Hi!

    I am new to Qt am making a QTreeView displaying a list of different objects. I want to be able to double click one of them and change it's name. Preferably, when the object is double clicked, the old name should be selected so the user can delete it by start write the new name and press enter.

    I have looked around and can't really decide what to do... should I implement a class inheriting QItemDelegate? Or is this functionality already implemented?

    I tried to use setModelData() but got the error:
    "property("text") failed: property invalid or does no exist."

    When reading the Model/View introduction on Trolltechs homepage I get the impression that there already are a lot of functionality implemented, but when I look at the documentation for the setEditorData() it says that it does nothing in the base implementation. So I'm a bit confused. I am a bit tired of finding out that the functionality already exist when I made a own implementation, so I thought that it would be a good idee to look around first but I can't find much about this.

    Any tips or examples to share?


    /pir

  2. #2
    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: Should I implement an own version of QItemDelegate for QTreeView?

    It's all there. All you need to do is to set appropriate edit triggers in the tree (QAbstractItemView::DoubleClicked in your case). And of course the model should allow editing (QAbstractItemModel::setData() should be implemented).

  3. #3
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Should I implement an own version of QItemDelegate for QTreeView?

    Thanks!

    When I double click the object I want to change, the string can be changed to another. But the text is not highlighted... you know when you mark a text with the mouse. How do I make the text highlighted when I double click the text to start editing?

    /pir

  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: Should I implement an own version of QItemDelegate for QTreeView?

    Quote Originally Posted by pir
    When I double click the object I want to change, the string can be changed to another. But the text is not highlighted... you know when you mark a text with the mouse. How do I make the text highlighted when I double click the text to start editing?
    I think you might have to reimplement QItemDelegate::setEditorData() for this.
    First, call the base class implementation which sets the correct data in the editor for you.
    Then cast the editor widget to a line edit and call QLineEdit::selectAll().
    J-P Nurmi

Similar Threads

  1. Designer doesn't load wwWidgets plugin
    By reimer in forum Installation and Deployment
    Replies: 21
    Last Post: 7th February 2009, 03:23
  2. Qt designer plugin errors on OSX Leopard
    By mpotocnik in forum Qt Tools
    Replies: 10
    Last Post: 21st January 2008, 09:45
  3. Replies: 2
    Last Post: 5th November 2007, 21:47
  4. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  5. Replies: 15
    Last Post: 21st April 2007, 17:46

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.