PDA

View Full Version : How to get a QPixmap from a QTableWidgetItem?



gboelter
9th October 2010, 19:01
Sorry guys & girls,

it's late and I'm tired but I have to fix something in my code, something where I could not figure out where I'm wrong.

The question is simple: How can I get a QPixmap from a QTableWidgetItem?

I have tried so many already but's all not working. Guess I should go to bed, but I'm really under pressure with that.

Why this code for example



QPixmap pixmap = QPixmap::grabWidget( currentItem(), 0, 0, 158, 18 );

gives me:



error: no matching function for call to ‘QPixmap::grabWidget(QTableWidgetItem*, int, int, int, int)’
.....
candidates are: static QPixmap QPixmap::grabWidget(QWidget*, const QRect&)
static QPixmap QPixmap::grabWidget(QWidget*, int, int, int, int)

Where I'm to blind to the the trees in the forrest tonight?

Lykurg
9th October 2010, 19:18
See the QTableWidgetItem::data() with the decoration role.

tbscope
9th October 2010, 19:55
A QTableWidgetItem is not a QWidget, so grabWidget does not work.
What do you want to achieve? Do you want to make a pixmap of one item in the table?

gboelter
9th October 2010, 20:03
Some days are like that ...


A QTableWidgetItem is not a QWidget, so grabWidget does not work.
I know, I should stop for today, I'm so tired ... :mad:



What do you want to achieve? Do you want to make a pixmap of one item in the table?
Yes, that's exactly what I like to do ...

Any idea how to do that?

gboelter
10th October 2010, 05:15
See the QTableWidgetItem::data() with the decoration role.

Thanks Lykurg!

Have tried this now ...



QPixmap TableWidget::selectedPixmap() const
{
if ( !currentItem() )
{
qDebug() << "no item found ...";
return QPixmap();
}
else
{
qDebug() << "current item is" << currentItem();
return currentItem()->data( Qt::DecorationRole ).value<QPixmap>();
}
}

but's still the same.

qDebug() returns 'current item is 0x1422a10'
qDebug() << currentItem()->data( Qt::DecorationRole ) returns ''QVariant(QString, "ArtMatch")'

But QSize returns 'QSize(-1, -1)'!

For testing I have tried to set my pixmap from an image with


QPixmap pixmap( ":/images/ampel_rot.jpg" );
With that my programm will work, but I need a pixmap with the content of currentItem()!

Any other ideas?

Lykurg
10th October 2010, 09:19
Ok, I get you wrong. If you need to render a whole item then use QTableWidget::visualItemRect() with QWidget::render() of the table widget.

wysota
10th October 2010, 09:43
You can call the delegate to render the item.

gboelter
10th October 2010, 10:49
If you need to render a whole item then use QTableWidget::visualItemRect() with QWidget::render() of the table widget.
Thanks Lykurg,

got it working in that way.

Thank you very much!!!

gboelter
10th October 2010, 10:52
You can call the delegate to render the item.
Thanks wysota,

will try it next time with delegate because I have never used delegate before.

For now it's fixed with the help from Lykurg.

I really love the forum here!!!