Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SOLVED: Scale image in Table Widget Cell
Forum Updated to NodeBB v4.3 + New Features

SOLVED: Scale image in Table Widget Cell

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qatto
    wrote on last edited by
    #1

    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

    Web/Desktop Developer

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qatto
        wrote on last edited by
        #3

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

        Web/Desktop Developer

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved