PDA

View Full Version : Get QTableWidget Cell width and height



mayrhofer
19th December 2015, 16:40
Hi everyone,

I want to resize a QLabel(in the labels are images) to fit in a cell. I use

label->setFixedSize(ui->tableWidget->columnWidth(currentColumn),ui->tableWidget->rowHeight(currentRow));
to set the labels size and than

QPixmap p=QPixmap(iterator->next());

label->setPixmap(p.scaled(label->width(),label->height(),Qt::KeepAspectRatio));
to keep the image aspect ratio. I get the currentColumn/Row from a selectionmodel.

When the cell doesn´t have row/colspan all works fine. But when i span (for example 2 rows) then i only get the height of the first row and i want to get the height of r1+r2. So the Image only fit the size of the first cell before the span and ignores the additional size from the span.


I didn´t find something about cellwidth/cellheight so I´m asking here now.


(And sorry for my bad english)

d_stranz
19th December 2015, 18:27
Probably need to call the base class QTableWidget::rowSpan() and/or QTableWidget::columnSpan() methods and then query for the heights / widths of the additional rows if either method returns > 1.

mayrhofer
21st December 2015, 07:19
I can't find these methods...

d_stranz
21st December 2015, 17:54
Sorry, I miss-typed. I meant QTableView. Always look in the base classes for functionality that is "missing" from the class you are instantiating.

mayrhofer
22nd December 2015, 12:39
Ok i'll try and reply after

mayrhofer
24th December 2015, 12:33
can you post an example of how to use this? i don´t know how to get to the parent´s method.

anda_skoa
24th December 2015, 13:13
You just call them like any other method.
A QTableWidget is a QTableView.

Cheers,
_