Add Qlabel as item in QTableview
sayan275 last edited by
How to add a qlabel(with qpixmap in it) in QTableview as each cell item?
so that the ouput looks like the image.
I tried with
- Qtablewidget and QTableitemwidget with seticon on item, but that makes the image as icon..ie a small one in the left with a available text space on the right.
QTableWidget* signImageTable = new QTableWidget(); QPixmap iconPixmap; iconPixmap.load("No_Passing.png"); QTableWidgetItem* imageLabel = new QTableWidgetItem(); imageLabel->setIcon(QIcon(iconPixmap)); signImageTable->setItem(rowCounter, colCounter++, imageLabel);
- I tried with QTableView and setIcon on each item, which had the same output
QTableView* m_pTableWidget = new QTableView(this); QStandardItem* item = new QStandardItem(); item->setIcon(QIcon(pixmap)); standardItemmodel->setItem(rowCounter, colCounter++, item); m_pTableWidget->setModel(model);
So, maybe set icon makes it shrink. QLabel with setPixamp set on it and adding them as qstandardItem in the tableview's model will look as expected.
I need the tableview as, the selected image name is required.
Please suggest how to add qlabel as item in QTableView!
3rd option: implement a custom QStyledItemDelegate to draw the image the way you want it.
sayan275 last edited by sayan275
Ok..I'll try with that.
from google search maybe this kind of output it will give, which maybe as our requirement.
Else, I have some lengthy approach..implement custom label with mousepressevent handled which emits the object name and add these custom labels, 20 in HLayout and add hlayouts in a vlayout...