Results 1 to 4 of 4

Thread: delegates

  1. #1
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default delegates

    I am learning QTableWidget.I wanted to show only images at QTableWidgetItems.So I tried to add labels to tablewidget cells.(there is an example:QSpinBox).
    Is there another way of this:Because if I use QTableWidgetItem ->icon() function;I can still show a linedit in cells.But I want only images.

  2. #2
    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: delegates

    Do you mean that you would like icons to fill whole cell?
    J-P Nurmi

  3. #3
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: delegates

    yes.all cell will show image.

  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: delegates

    It should be as simple as subclassing QItemDelegate and reimplementing QItemDelegate::paint() more or less in the following way:
    Qt Code:
    1. void MyItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    2. {
    3. QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
    4. drawBackground(painter, option, index);
    5. drawDecoration(painter, option, option.rect, icon.pixmap(option.rect.size()));
    6. drawFocus(painter, option, option.rect);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Then set the delegate to your table widget and use QTableWidgetItem::setIcon() to set icons.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    hgedek (25th October 2007)

Similar Threads

  1. animations in Interview Delegates
    By eean in forum Qt Programming
    Replies: 5
    Last Post: 8th August 2007, 23:00
  2. Setting Delegates per Column
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2006, 21:39
  3. Delegates and Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2006, 19:47

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.