SOLVED: Scale image in Table Widget Cell
-
Hello,
I am trying to scale an image with scaledtoHeight() so it can fit in a tableWidget cell. But the image is displayed in its real size so only part of it is shown. I looked up the problem and saw someone had put the image inside a layout. But the image still can't be scaled properly, Please look at the code below and help me out:@QLabel *imageLabel = new QLabel;
QPixmap *image = new QPixmap(":/images/pack.png");
image->scaledToHeight(50);
imageLabel->setPixmap(image);
QWidget wdg = new QWidget;
QHBoxLayout *Layout = new QHBoxLayout(wdg);
Layout->addWidget(imageLabel);
Layout->setMargin(0);
Layout->setAlignment(Qt::AlignCenter);
wdg->setLayout(Layout);
ui->tableWidget->setCellWidget(0, 1, wdg);@Thanks in Advance
-
Hi, scaledToHeight returns a copy of the image.
Change your code with:
@
QPixmap image(":/images/pack.png");
imageLabel->setPixmap(image.scaledToHeight(50);
@And you should be good
-
Thanks SGalst, it worked. But how do I mark a discussion as SOLVED
-
You're welcome !
Simply prepend solved to the thread's title and you're good