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. resize a cell of qtablewidget
Forum Updated to NodeBB v4.3 + New Features

resize a cell of qtablewidget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 585 Views
  • 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.
  • AlbatorA Offline
    AlbatorA Offline
    Albator
    wrote on last edited by Albator
    #1

    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 :)

    JonBJ 1 Reply Last reply
    0
    • AlbatorA Albator

      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 :)

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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!

      AlbatorA 2 Replies Last reply
      0
      • JonBJ JonB

        @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!

        AlbatorA Offline
        AlbatorA Offline
        Albator
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • JonBJ JonB

          @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!

          AlbatorA Offline
          AlbatorA Offline
          Albator
          wrote on last edited by Albator
          #4

          @JonB the solution are very sample

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

          thanks for your help :)

          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