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. unable to update QTableView cell text
Forum Updated to NodeBB v4.3 + New Features

unable to update QTableView cell text

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • I Offline
    I Offline
    iradarann
    wrote on last edited by
    #1

    I am trying to edit text in QTableView cell (update text base on another table) but I am unable to do any changes. Below is my code but it does not work.

    QTime time = ui->tv_timeSlot->model()->data(ui->tv_timeSlot->model()->index(index.row(),index.column())).toTime();
    QString timeStr = time.toString("hh:mm:ss");
    ui->tv_timeCard->model()->setData(ui->tv_timeCard->model()->index(1,1),timeStr,Qt::EditRole);
    

    I did find out that there are some people override the flags function with

    Qt::ItemFlags MyTableModel::flags (const QModelIndex &index) const
    {
        return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
    }
    

    I would prefer not to override the function because I had no basic on this. But if that is the only way, please guide me. Thanks in advance

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2
      • ui->tv_timeCard->model()->index(1,1) does your model have at least 2 rows and 2 columns?
      • ui->tv_timeCard->model()->setData returns a boolean, you should check what value it is
      • Can you try using QStandardItemModel instead of MyTableModel?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      I 1 Reply Last reply
      1
      • VRoninV VRonin
        • ui->tv_timeCard->model()->index(1,1) does your model have at least 2 rows and 2 columns?
        • ui->tv_timeCard->model()->setData returns a boolean, you should check what value it is
        • Can you try using QStandardItemModel instead of MyTableModel?
        I Offline
        I Offline
        iradarann
        wrote on last edited by
        #3

        @VRonin Thanks for the suggestion.

        • I have 37 columns and 20+ rows
        • It return false. I am wondering why it unable to update and return false.
        • How can i know if i am using QStandardItemModel or MyTableModel? Or is there any way to set it?
        VRoninV 1 Reply Last reply
        0
        • I iradarann

          @VRonin Thanks for the suggestion.

          • I have 37 columns and 20+ rows
          • It return false. I am wondering why it unable to update and return false.
          • How can i know if i am using QStandardItemModel or MyTableModel? Or is there any way to set it?
          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @iradarann said in unable to update QTableView cell text:

          It return false. I am wondering why it unable to update and return false.

          You can step into it with the debugger to find out

          How can i know if i am using QStandardItemModel or MyTableModel? Or is there any way to set it?

          This is set when you call QTableView::setModel

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1

          • Login

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