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. Remove the textfield near the checkable QTableView cells
Qt 6.11 is out! See what's new in the release blog

Remove the textfield near the checkable QTableView cells

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 545 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.
  • lmofallisL Offline
    lmofallisL Offline
    lmofallis
    wrote on last edited by lmofallis
    #1

    Hello,

    Is there a way to remove or hide the textfield near the checkbox on the QTableView?
    I tried several things without any success.
    System : Linux mint.
    Qt version : 6.4.2

    de8c042d-08ec-4827-be1d-36ac3437da74-image.png

    This feature is so ugly & annoying.

    1 Reply Last reply
    0
    • lmofallisL lmofallis

      There is a sample of my code :

      QStandardItemModel *model = new QStandardItemModel(3, 3, this);
      
      model->setHeaderData(0, Qt::Horizontal, tr("Select"));
      model->setHeaderData(1, Qt::Horizontal, tr("Column 1"));
      model->setHeaderData(2, Qt::Horizontal, tr("Column 2"));
      
      for (int row = 0; row < model->rowCount(); row++) {
      
          QStandardItem *checkItem = new QStandardItem();
          checkItem->setCheckable(true);
          checkItem->setEditable(false);
          checkItem->setCheckState(Qt::Unchecked);
          model->setItem(row, 0, checkItem);
      
          model->setData(model->index(row, 1), tr("Row %1 Column 1").arg(row+1));
          model->setData(model->index(row, 2), tr("Row %1 Column 2").arg(row+1));
      }
      
      ui->tableView->setModel(model);
      ui->tableView->setColumnWidth(0, 20);
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      You have to use a custom QStyledItemDelegate: https://wiki.qt.io/Center_a_QCheckBox_or_Decoration_in_an_Itemview

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

      lmofallisL 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        How did you put your checkbox there ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • lmofallisL Offline
          lmofallisL Offline
          lmofallis
          wrote on last edited by
          #3

          There is a sample of my code :

          QStandardItemModel *model = new QStandardItemModel(3, 3, this);
          
          model->setHeaderData(0, Qt::Horizontal, tr("Select"));
          model->setHeaderData(1, Qt::Horizontal, tr("Column 1"));
          model->setHeaderData(2, Qt::Horizontal, tr("Column 2"));
          
          for (int row = 0; row < model->rowCount(); row++) {
          
              QStandardItem *checkItem = new QStandardItem();
              checkItem->setCheckable(true);
              checkItem->setEditable(false);
              checkItem->setCheckState(Qt::Unchecked);
              model->setItem(row, 0, checkItem);
          
              model->setData(model->index(row, 1), tr("Row %1 Column 1").arg(row+1));
              model->setData(model->index(row, 2), tr("Row %1 Column 2").arg(row+1));
          }
          
          ui->tableView->setModel(model);
          ui->tableView->setColumnWidth(0, 20);
          
          Christian EhrlicherC 1 Reply Last reply
          0
          • lmofallisL lmofallis

            There is a sample of my code :

            QStandardItemModel *model = new QStandardItemModel(3, 3, this);
            
            model->setHeaderData(0, Qt::Horizontal, tr("Select"));
            model->setHeaderData(1, Qt::Horizontal, tr("Column 1"));
            model->setHeaderData(2, Qt::Horizontal, tr("Column 2"));
            
            for (int row = 0; row < model->rowCount(); row++) {
            
                QStandardItem *checkItem = new QStandardItem();
                checkItem->setCheckable(true);
                checkItem->setEditable(false);
                checkItem->setCheckState(Qt::Unchecked);
                model->setItem(row, 0, checkItem);
            
                model->setData(model->index(row, 1), tr("Row %1 Column 1").arg(row+1));
                model->setData(model->index(row, 2), tr("Row %1 Column 2").arg(row+1));
            }
            
            ui->tableView->setModel(model);
            ui->tableView->setColumnWidth(0, 20);
            
            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            You have to use a custom QStyledItemDelegate: https://wiki.qt.io/Center_a_QCheckBox_or_Decoration_in_an_Itemview

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

            lmofallisL 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              You have to use a custom QStyledItemDelegate: https://wiki.qt.io/Center_a_QCheckBox_or_Decoration_in_an_Itemview

              lmofallisL Offline
              lmofallisL Offline
              lmofallis
              wrote on last edited by
              #5

              @Christian-Ehrlicher

              It's working.

              But, I have 2 questions:
              1- I'm not used to work with delegate. So Is is a good solution?
              2- How can I minimize the column width to fit the checkbox?

              d40468bc-9728-4684-8d32-42138cf52875-image.png

              1 Reply Last reply
              0
              • lmofallisL lmofallis has marked this topic as solved on

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved