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. How to turn off selection cells by tab and shif+tab in QTableWidget in slot?
Forum Updated to NodeBB v4.3 + New Features

How to turn off selection cells by tab and shif+tab in QTableWidget in slot?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 262 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.
  • K Offline
    K Offline
    Kuji
    wrote on last edited by Kuji
    #1

    I turn on editing some columns of QTableWidget by this

    QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
                             ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) {
                if(index.column()!=0&&index.column()!=7&&index.column()!=8&&index.column()!=9)
                    if (ui->tableWidgetAdminEmployee->item(index.row(), index.column())->flags() & Qt::ItemIsEnabled )
                        ui->tableWidgetAdminEmployee->edit(index);
            });
    

    But if i choose editable cell and then start editing it and press tab next cell will be selected and become editable even if it shouldn't

    I turned off tabKeyNavigation in QTableWidget, but editable cells still can be selected by tab

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kuji
      wrote on last edited by
      #2

      Solved

      for(int row=0; row<ui->tableWidgetAdminEmployee->rowCount(); row++){
              for(int col=0; col< ui->tableWidgetAdminEmployee->columnCount(); col++){
                  auto item=new QTableWidgetItem;
                  if(col==0 || col==7 || col==8|| col==9)
                      item->setFlags(item->flags() &  ~Qt::ItemIsEditable); //non-editable columns
                  ui->tableWidgetAdminEmployee->setItem(row, col, item);
              }
          }
          
          ui->tableWidgetAdminEmployee->setSelectionMode(QAbstractItemView::NoSelection);
          ui->tableWidgetAdminEmployee->setEditTriggers(QAbstractItemView::NoEditTriggers);
      
          QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
                           ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) {
      
              if (ui->tableWidgetAdminEmployee->item(index.row(), index.column())->flags() & Qt::ItemIsEditable )
                  ui->tableWidgetAdminEmployee->edit(index);
          });
      
      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