Results 1 to 5 of 5

Thread: display custom widget in a TableView

  1. #1
    Join Date
    Apr 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question display custom widget in a TableView

    Hi,

    have my own model that holds my own custom datatype in a custom role. Now I want to display the content of the model in an item view (QTableView). I read about Delegates, but I have a problem to use them correctly.

    I wrote a delegate that creates a custom editor widget for my datatype using createEditor()/setEditorData().

    This works, but the custom editor widget is only displayed when I doubleclick a cell to start editing.

    I also want to use my custom editor widget for normal display of the items, but there is no "createViewer()" like method in QStyledItemDelegate. It seems that I have to override the paint() method of the delegate in order to influence the display of my items. But now, I'm lost. How can I get Qt to render my custom display widget in the paint() method of the delegate?

  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: display custom widget in a TableView

    I also want to use my custom editor widget for normal display of the items,
    You will need to handle mouse and paint events yourself.. ie. in the paint of delegate, you will have to paint your custom widget through QStyle painter and handle the mouse / key events

    Setting widget for each cell wont be a good idea.

  3. #3
    Join Date
    Apr 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display custom widget in a TableView

    Thank you for this hint. It is not what I need, but it brought me on the right track.

    I need some interaction in my custom widget, therefore painting it with the delegate is rather cumbersome. I now got it to work to just set the widgets with setIndexWidget(). This works as expected and I can guarantee, that there will be <20 items in the table, so performance should be okay.

  4. #4
    Join Date
    May 2012
    Location
    India
    Posts
    51
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: display custom widget in a TableView

    but through QItemDelegate we can only display the widget during editing the cell..
    Is there any way to display it permanently ?

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: display custom widget in a TableView

    Well, you can use QAbstractItemView::openPersistentEditor, but it can "slow down" your view if there are a lot of data.
    I would suggest to grab an editor using QPixmap::grabWidget or even better to render it using QWidget::render in the item's delegate QItemDelegate::paint method.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. TableView/Model Display Question
    By SixDegrees in forum Qt Programming
    Replies: 9
    Last Post: 27th August 2010, 10:06
  2. custom a display widget that can take input from touch panel
    By wesley in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 25th January 2010, 09:49
  3. Replies: 1
    Last Post: 12th October 2009, 10:33
  4. Replies: 5
    Last Post: 16th May 2006, 21:38
  5. Replies: 3
    Last Post: 12th April 2006, 09:20

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.