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!
Re: QTreeWidget - setPixmap???
Maybe a QListWidget in QListView::IconMode suits you better?
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 :)
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?
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 :(
Re: QTreeWidget - setPixmap???
Try setting uniform row heights off and appropriate size hints for every item containing an item widget:
Code:
treeWidget->setUniformRowHeight(false);
// ...
// for each item:
treeWidgetItem->setSizeHint(col, widget->sizeHint()); // same size hint for the item than the item widget has
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 :mad: :mad: :mad:
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 :crying:
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...
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...
Quote:
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
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.
1 Attachment(s)
Re: QTreeWidget - setPixmap???
Quote:
Originally Posted by
durbrak
Oh my god... all I want is a QPixmap centered in a cell :crying:
Just a pixmap? Like this?
Re: QTreeWidget - setPixmap???
Yes! Kinda like this.
How'd you do that?
Re: QTreeWidget - setPixmap???
I used a custom delegate like this:
Code:
// a sensible maximum size for the icons
static const int MAX_HEIGHT = 100;
static const int MAX_WIDTH = 100;
void ItemDelegate
::paint(QPainter* painter,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
QIcon icon
= qvariant_cast<QIcon>
(index.
data(Qt
::DecorationRole));
QSize size
= icon.
actualSize(QSize(MAX_HEIGHT, MAX_WIDTH
));
QRect rect
= qApp
->style
()->alignedRect
(qApp
->layoutDirection
(), Qt
::AlignCenter, size, option.
rect);
painter
->drawPixmap
(rect, icon.
pixmap(QSize(MAX_HEIGHT, MAX_WIDTH
)));
// draw selection here..?
// let the base class implementation draw focus?
}
QSize ItemDelegate
::sizeHint(const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
QIcon icon
= qvariant_cast<QIcon>
(index.
data(Qt
::DecorationRole));
return icon.
actualSize(QSize(MAX_HEIGHT, MAX_WIDTH
));
}