Results 1 to 4 of 4

Thread: Adding custom widget to a Model-View table

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,313
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding custom widget to a Model-View table

    Well, there's QAbstractItemView::setIndexWidget(). Unfortunately, these widgets aren't connected to the model in any way. However, I think if you derive a delegate of you own and override the QAbstractItemDelegate::paint() method, you can draw whatever you want in the cell and it will be visible whether it is being edited or not.

  2. #2
    Join Date
    Jul 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding custom widget to a Model-View table

    Thanks for the response. I'll try and work with the QAbstractItemDelegate -- I've never had to paint and existing QWidget (like the group of QPushButtons that I have) but I assume that I can just call its paint function or something along those lines.

    I suppose I could also make the setItemWidget work, but that would imply that my model owns the majority of the data in the tree aside from one column so if it does work, it would be a sort of hybrid between the TreeView and the TreeWidget.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,313
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding custom widget to a Model-View table

    I assume that I can just call its paint function or something along those lines.
    Well, no. You are inserting a delegate, not a widget, and since the paintEvent method for a QWidget is protected, you can't call the QPushButton's paintEvent() from an unrelated class. Look into QProxyStyle::drawControl() and QStyleOption::initFrom(). These are ways to draw something that looks like a widget but isn't (and are the way Qt draws actual widgets).

Similar Threads

  1. model view pixmap table help
    By Bennieboj in forum Newbie
    Replies: 4
    Last Post: 12th November 2011, 12:38
  2. adding image to header column of a table view
    By nageshvk in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2011, 04:14
  3. Q Table View + Relational Model VERY SLOW
    By arimaniac in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2010, 16:43
  4. Replies: 33
    Last Post: 7th December 2009, 10:11
  5. Table view->model->set data
    By tulsi in forum Qt Programming
    Replies: 3
    Last Post: 21st April 2009, 08:36

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.