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. Add QCheckBox in every cells of a column in QTable Widget
QtWS25 Last Chance

Add QCheckBox in every cells of a column in QTable Widget

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidgetqcheckbox
3 Posts 2 Posters 827 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.
  • A Offline
    A Offline
    aim0d
    wrote on last edited by aim0d
    #1

    Hi!
    I'm new to QT and I'm trying to create a table using QTableWidget and I would like to insert QCheckboxes in the first column, like this:63a628a1-5341-49a9-bb98-d58d2b994fa5-tab.png

    This is the code I use (for every cells) in this example:

    QHBoxLayout *j = new QHBoxLayout();
        z->addWidget((new QCheckBox("")));
        QWidget *q = new QWidget();
        z->setLayout(j);
       ui->tableWidget->setCellWidget(0,0, z);
    

    Is there a way to do it more automatically, without repeat the code 10times?
    Thanks!

    Christian EhrlicherC 1 Reply Last reply
    0
    • A aim0d

      Hi!
      I'm new to QT and I'm trying to create a table using QTableWidget and I would like to insert QCheckboxes in the first column, like this:63a628a1-5341-49a9-bb98-d58d2b994fa5-tab.png

      This is the code I use (for every cells) in this example:

      QHBoxLayout *j = new QHBoxLayout();
          z->addWidget((new QCheckBox("")));
          QWidget *q = new QWidget();
          z->setLayout(j);
         ui->tableWidget->setCellWidget(0,0, z);
      

      Is there a way to do it more automatically, without repeat the code 10times?
      Thanks!

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @aim0d said in Add QCheckBox in every cells of a column in QTable Widget:

      Is there a way to do it more automatically, without repeat the code 10times?

      Put your logic in a loop for every row.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @aim0d said in Add QCheckBox in every cells of a column in QTable Widget:

        Is there a way to do it more automatically, without repeat the code 10times?

        Put your logic in a loop for every row.

        A Offline
        A Offline
        aim0d
        wrote on last edited by
        #3

        @Christian-Ehrlicher Oh, so stupid of mine for not thinking about it ahha
        thanks!

        RESULT for future noobie like me:

        for(int row=0;row<=12;row++){
             QHBoxLayout *a = new QHBoxLayout();
             a->addWidget((new QCheckBox("")));
             QWidget *z = new QWidget();
              z->setLayout(a);
              ui->tableWidget->setCellWidget(row,0, z);
        }
        
        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