Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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?

        ui->tableWidget->setRowCount(10);
        ui->tableWidget->setColumnCount(3);
    
        QStringList liste;
        liste << "Step" << "Value coder" << "Picture";
        ui->tableWidget->setHorizontalHeaderLabels(liste);
    
      
    
    
    
    
        QPixmap pix("C:/Users/portalc/Pictures/atm3/pos_init.png");
        QPixmap resPix = pix.scaled(300,300, Qt::KeepAspectRatio, Qt::FastTransformation);
        QLabel *lblTest = new QLabel;
        lblTest->setPixmap(resPix);
        lblTest->setAlignment(Qt::AlignCenter);
        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

     ui->tableWidget->resizeRowsToContents();
     ui->tableWidget->resizeColumnsToContents();
    

    thanks for your help :)


Log in to reply