Results 1 to 3 of 3

Thread: Delegate & widgets

  1. #1
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Delegate & widgets

    Hi, I need to implement a delegate for a QListView widget which paints, for each item (taken from a sql table model), a pair composed by a QLabel and a QLineEdit instances.

    How can i do it?

    Qt Code:
    1. void MyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    2. {
    3. // ... ??
    4. }
    To copy to clipboard, switch view to plain text mode 

    I need "real widgets" instead of "painted-only widgets", so i can connect signals and slots for my specific logic.

    Thanks for your help!

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Delegate & widgets

    you can use the WA_DontShowOnScreen widget attribute. you can make real widgets with that attribute set to true, then install eventFilter() on them and call update on proper index while you catch PaintEvent. in paint you can use QWidget::render() to render the widget (for me it is working to render it on a pixmap and than paint the pixmap in the view). Unfotunately you have to catch events like mouse in the editorEvent() and pass it to the proper widget, which require some work.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Delegate & widgets

    If you don't have too many rows, I think you can call QAbstractItemView::setIndexWidget. However, I don't know if this is recommended.

Similar Threads

  1. Qt3 - Multiple transparent widgets
    By bythesea in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2009, 11:24
  2. Upper limit on number of widgets?
    By jdiewald in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2008, 23:00
  3. Delegate for a certain item?
    By somebody in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2008, 22:55
  4. Replies: 2
    Last Post: 16th May 2008, 14:39
  5. widgets behind hidden widgets not working
    By bpetty in forum Newbie
    Replies: 13
    Last Post: 7th September 2007, 20:23

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.