Results 1 to 13 of 13

Thread: QTreeWidget - setPixmap???

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidget - setPixmap???

    Hello,
    in Qt3 I always used QListView and QListViewItem::setPixmap() to put picture in cells instead of text. Now in Qt4 the replacement for QListView seems to be QTreeWidget with its QTreeWidgetItems... but QTreeWidgetItems doesn't have something like setPixmap()... only setIcon() and setData(0, Qt::DecorationRole, pixmap) but those behave like i'm setting some icon instead of a picture.
    So with setIcon() my picture is being resized to 16x16 (I CANNOT use QTreeWidget::setIconSize() since my pixmaps have all different dimensions)... with setData() (as DecorationRole) my pixmap is being cut off at left and down...
    What's Qt4's way of handling this?

    Thank you for your help in advance!

  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: QTreeWidget - setPixmap???

    Maybe a QListWidget in QListView::IconMode suits you better?
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget - setPixmap???

    Unfortunately the QListWidget isn't the type of view I need. My View has got to have columns and a Header and QListWidget is just a simple list box with widgets in it

  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: QTreeWidget - setPixmap???

    I have a feeling that QItemDelegate might not be flexible enough for this. However, maybe you could make use of item widgets?
    J-P Nurmi

  5. #5
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget - setPixmap???

    I already tried that by setting a QPixmap on a QLabel and putting that QLabel in the QTreeWidget via setItemWidget() but the widget is being cut off (row is not high enough).
    I'm having a feeling that TT forgot to integrate this 'simple' feature

  6. #6
    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: QTreeWidget - setPixmap???

    Try setting uniform row heights off and appropriate size hints for every item containing an item widget:
    Qt Code:
    1. treeWidget->setUniformRowHeight(false);
    2. // ...
    3. // for each item:
    4. treeWidgetItem->setSizeHint(col, widget->sizeHint()); // same size hint for the item than the item widget has
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. #7
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget - setPixmap???

    I'm about to freak out...
    I now use my own QTreeView and my own QStandardItemModel but this whole Qt:: DecorationRole instead of the good old Qt3 setPixmap()-method is just pure BS
    I've been sitting on a solution for this for 3 days constantly now and I think I'm about to have a heart attack... this cr*p is driving me crazy... my QItemDelegate::drawDecoration()'s QRect supplies some screwed up positions, I played around with setIndexWidget(), with QStyleOptionViewItem::displayPosition, Qt::SizeHintRole... everything! Nothing will work...
    It's like the Trolls did that on purpose...
    Oh my god... all I want is a QPixmap centered in a cell

  8. #8
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget - setPixmap???

    Oh and by the way..
    I put a QSortProxyFilterModel between my model and my view... in my QTreeView I setIconSize() to some big values like 100x100 and when I click on the headers to sort something it works fine... but when i move the vertical scrollbar to the right until the decoration from the first column isn't visible anymore and click on the header again to sort something - each row gets small like 16px high and when i scroll back to the left my decoration-icon is cut off again...

  9. #9
    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: QTreeWidget - setPixmap???

    Are you aware of Qt3Support module? You can always use Q3ListView if you're not satisfied with Qt 4's corresponding classes...

    The Qt3Support module provides classes that ease porting from Qt 3 to Qt 4.

    To include the definitions of the module's classes, use the following directive:

    #include <Qt3Support>

    To link against the module, add this line to your qmake .pro file:

    QT += qt3support
    J-P Nurmi

  10. #10
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget - setPixmap???

    Yeah, I know about this. But 'downgrading' is not an option to me since I wanna make use of the (oh so mighty) Model/View-Framework because I wanna provide different view options to my users and I don't want to write 10 different itemwidgets.

  11. #11
    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: QTreeWidget - setPixmap???

    Quote Originally Posted by durbrak View Post
    Oh my god... all I want is a QPixmap centered in a cell
    Just a pixmap? Like this?
    Attached Images Attached Images
    J-P Nurmi

  12. #12
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget - setPixmap???

    Yes! Kinda like this.
    How'd you do that?

  13. #13
    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: QTreeWidget - setPixmap???

    I used a custom delegate like this:
    Qt Code:
    1. // a sensible maximum size for the icons
    2. static const int MAX_HEIGHT = 100;
    3. static const int MAX_WIDTH = 100;
    4.  
    5. void ItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    6. {
    7. QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
    8. QSize size = icon.actualSize(QSize(MAX_HEIGHT, MAX_WIDTH));
    9. QRect rect = qApp->style()->alignedRect(qApp->layoutDirection(), Qt::AlignCenter, size, option.rect);
    10. painter->drawPixmap(rect, icon.pixmap(QSize(MAX_HEIGHT, MAX_WIDTH)));
    11. // draw selection here..?
    12.  
    13. // let the base class implementation draw focus?
    14. QItemDelegate::drawFocus(painter, option, option.rect);
    15. }
    16.  
    17. QSize ItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
    18. {
    19. QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
    20. return icon.actualSize(QSize(MAX_HEIGHT, MAX_WIDTH));
    21. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  2. Replies: 1
    Last Post: 21st September 2006, 10:37
  3. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50
  4. QTreeWidget problem!!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2006, 11:47
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.