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. <SOLVED> How to forbid only empty cells in a QTableWidget from selection (or to allow a certain CellWidget() to be selected)
Forum Updated to NodeBB v4.3 + New Features

<SOLVED> How to forbid only empty cells in a QTableWidget from selection (or to allow a certain CellWidget() to be selected)

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtablewidgetselection
3 Posts 2 Posters 3.4k 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.
  • O Offline
    O Offline
    Olivier Ronat
    wrote on 10 Dec 2015, 09:08 last edited by Olivier Ronat 12 Oct 2015, 10:09
    #1

    Hello
    I'm using a QTableWidget and I populate some cells with widgets with setCellWidget( row, column, &widget)..
    I want to be able to select only cells with widget but not empty cells.
    How to achieve it?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 10 Dec 2015, 09:29 last edited by
      #2

      Something like this should do the trick:

      for(int i = 0; i < table->rowCount(); ++i) {
          for(int j = 0; j < table->columnCount(); ++j) {
              auto item = table->item(i, j);
              if(!item) { // make sure there's an item in that cell
                  item= new QTableWidgetItem();
                  table->setItem(i, j, item);
              }
              if(!table->cellWidget(i,j))
                  item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
          }
      }
      
      1 Reply Last reply
      0
      • O Offline
        O Offline
        Olivier Ronat
        wrote on 10 Dec 2015, 10:09 last edited by
        #3

        Thank you
        Note that I succeed in first buiding my QTableWidget with each item set by item->setFlags(Qt::NoItemFlags) and then when I want to insert a wiget proceed with delete takeItem(row,column) before the setCellWidget(row, column, &widget) to insert a widget and retrieve the normal behavior

        1 Reply Last reply
        0

        3/3

        10 Dec 2015, 10:09

        • Login

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