PDA

View Full Version : QTableWidget Pixmap problem



batileon
4th September 2008, 11:34
How can I set a background pixmap in a cell of QTableWidget?

in QT3 , there is a

void QTable::setPixmap ( int row, int col, const QPixmap & pix ) [virtual]

If I change the QTable to QTableWidget, how can I complete the above task?

jacek
4th September 2008, 21:41
There are methods for setting a background texture or an icon, but I don't think you want that. You can subclass QTableWidgetItem and make it paint the pixmap.

BrainB0ne
5th September 2008, 09:40
Maybe its possible to use the following function on a QTableWidget:

QTableWidgetItem * QTableWidget::item ( int row, int column ) const
Returns the item for the given row and column if one has been set; otherwise returns 0.


after you got the QTableWidgetItem, use this function on it:

void QTableWidgetItem::setIcon ( const QIcon & icon )
Sets the item's icon to the icon specified.

ah by the way a QIcon can be created from a pixmap using the following constructor:

QIcon ( const QPixmap & pixmap )


Correct me if i am wrong, i am currently not working with Qt4, but i remember i did something like this in the past :)

no_barth
28th March 2018, 16:39
Use setData with Qt:: DecorationRole instead, to display an entire picture.


QTableWidgetItem *newItem = new QTableWidgetItem("");
QPixmap pixmap = myFunctionToLoadPixmap();
newItem->setData(Qt::DecorationRole, pixmap);
m_verticalRoadSignWidget->ui.mruTableWidget->setItem(0, 0, newItem);