Important: Please read the Qt Code of Conduct -

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");
    wdg = new QWidget;
    QHBoxLayout *Layout = new QHBoxLayout(wdg);
    ui->tableWidget->setCellWidget(0, 1, wdg);@

    Thanks in Advance

  • Lifetime Qt Champion

    Hi, scaledToHeight returns a copy of the image.

    Change your code with:
    QPixmap image(":/images/pack.png");

    And you should be good

  • Thanks SGalst, it worked. But how do I mark a discussion as SOLVED

  • Lifetime Qt Champion

    You're welcome !

    Simply prepend solved to the thread's title and you're good

Log in to reply