Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set cell size of QTableWidget?
Qt 6.11 is out! See what's new in the release blog

How to set cell size of QTableWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 10.2k 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by sonichy
    #1

    Solved:

    ui->tableWidget->horizontalHeader()->setDefaultSectionSize(60);    // width
    ui->tableWidget->verticalHeader()->setDefaultSectionSize(60);      // height
    ......
    ui->tableWidget->setCellWidget(r,c,widget);
    

    https://github.com/sonichy

    raven-worxR 1 Reply Last reply
    1
    • sonichyS sonichy

      Solved:

      ui->tableWidget->horizontalHeader()->setDefaultSectionSize(60);    // width
      ui->tableWidget->verticalHeader()->setDefaultSectionSize(60);      // height
      ......
      ui->tableWidget->setCellWidget(r,c,widget);
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @sonichy
      try:

      QTabelWIdgetItem* item = new QTableWidgetItem;
         item->setSizeHint( widget->sizeHint() );
      ui->tableWidget->setCellWidget(r,c,item);
      ui->tableWidget->setCellWidget(r,c,widget);
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        For the people ending here from google.
        The solution that avoids the awful setCellWidget is using a QStyledItemDelegate subclass that reimplements sizeHint()

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        3
        • F Offline
          F Offline
          frnklu20
          wrote on last edited by
          #4

          but how can i do this?

          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
          • Unsolved