Results 1 to 8 of 8

Thread: popup editors for QTreeView and QAbstractItemModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: popup editors for QTreeView and QAbstractItemModel

    Quote Originally Posted by ctgrund View Post
    am doing fine with QTreeView, abstract models, and delegates.
    What I need now is the following: In the tree there is a string and if I would like to edit it there should come something like the ... button.
    Then your delegate will create a button as the editor widget.

    Quote Originally Posted by ctgrund View Post
    When I click on it the file dialog pops up.
    Then you need to connect your button's clicked() signal to a slot that runs the file dialog.

    You could have your own button class that does that internally and has a member for the file name, which is set in setEditorData and read in setModelData.
    Or using a dynamic property on a normal QPushButton or storing the name elsewhere and accessing it from the slot that shows the dialog.

    I would go for a base class that encapsulates the dialog step

    Qt Code:
    1. class EditorButton : public QPushButton
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit EditorButton( QWidget *parent ) : QPushButton( parent )
    7. {
    8. connect( this, SIGNAL(clicked()), this, SLOT(onClicked()) );
    9. }
    10.  
    11. void setEditorData( const QVariant &data ); // store data delegate gets in setEditorData
    12. QVariant modelData() const; // return data that setModelData should store.
    13.  
    14. protected slots:
    15. virtual void onClicked() = 0; // implemented by sub classes
    16. }
    To copy to clipboard, switch view to plain text mode 

    EditorButton::setEditorData() could also set the button's text, but you can also do that in the delegate.
    It could also be subclass specific, i.e. using QString as the type for file names. depends on where you want to know about which class

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    ctgrund (22nd January 2014)

  3. #2
    Join Date
    Mar 2011
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6

    Default Re: popup editors for QTreeView and QAbstractItemModel

    Button will be the editor widget! Everything else I think I can do.
    Thanks!

Similar Threads

  1. QTreeView with QAbstractItemModel slow
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2012, 09:06
  2. QTreeView with QAbstractItemModel
    By Fletcher in forum Qt Programming
    Replies: 4
    Last Post: 10th December 2009, 23:02
  3. Creating a QAbstractItemModel for QTreeView
    By hbill in forum Qt Programming
    Replies: 13
    Last Post: 14th August 2008, 16:01
  4. Need help with QTreeView/QAbstractItemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th August 2006, 15:09
  5. [QT4] QTreeView, QAbstractItemModel and sorting
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2006, 20:16

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
  •  
Qt is a trademark of The Qt Company.