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 register adding row event to QTableWidget
Qt 6.12 LTS is out! See what's new in the release blog

How to register adding row event to QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 492 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.
  • SabracS Offline
    SabracS Offline
    Sabrac
    wrote on last edited by
    #1

    Hi guys,

    I have multiple QTableWidget in my desktop application,
    Currently, i assign them to use same custom context menu for adding, clone, remove row(s).
    But i stuck in case: each table have different condition check when add new row.

    For example: Column 1 in table A is text format, column 1 in table B is checkbox format (im using setCellWidget to assign checkbox), column 1 in table C is combobox format => So if in add new row menu action, just use table->insertRow(table->rowCount()) is not enough, all cell in new row have default text field.

    So, i wonder is there anyway to register adding row event on QTableWidget to create different cell format for each table?

    1 Reply Last reply
    0
    • SabracS Offline
      SabracS Offline
      Sabrac
      wrote on last edited by Sabrac
      #2

      My current workaround is set table not editable,

      Then, implement cell double click slot.

      In cell double click slot, detect which cell is clicking at, set correspond cell widget and then programmatically edit that cell like below

      QModelIndex index = this->ui->tableA->model()->index(row, column);
      this->ui->tableA->setCurrentIndex(index);
      this->ui->tableA->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
      • Unsolved