Important: Please read the Qt Code of Conduct -

resize a cell of qtablewidget

  • Hello i'm trying to set a picture in a cell of my tableWidget and is a little success but the size of cell is fixed and for me is not good.
    I'd like the cell to fit the size of the image, how do I do that?

        QStringList liste;
        liste << "Step" << "Value coder" << "Picture";
        QPixmap pix("C:/Users/portalc/Pictures/atm3/pos_init.png");
        QPixmap resPix = pix.scaled(300,300, Qt::KeepAspectRatio, Qt::FastTransformation);
        QLabel *lblTest = new QLabel;
        ui->tableWidget->setCellWidget(1, 2, lblTest);

    thanks for your help :)

  • @Albator
    I think you have to go item->setSizeHint( lblTest->sizeHint() );.

    Note that if @VRonin sees your proposed solution here of using setCellWidget() at all, he will come down on you like a ton of bricks and advise you to change over to a QStyledItemDelegate for this!

  • This post is deleted!

  • @JonB the solution are very sample


    thanks for your help :)

Log in to reply