Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Creating QModelIndex from QTableView row number

    General and Desktop
    1
    2
    7179
    Loading More Posts
    • 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.
    • M
      maximus last edited by

      I would like to create a QModelIndex from a row number in a QTableView.

      I know you can get the row from the QModelIndex (index.row())
      I'm wondering if you can go the opposite way?
      Reason I need a QModelIndex is that i'm drawing a custom QWidget on top of a QTableView and I need the function "visualRect(QModelIndex)" of QTableView in order to find the position on the screen.

      I tried adding a custom method in my QAbstractTableModel like this:
      @QModelIndex IntervalTableModel::getIndexAtRow(int row) {

      qDebug() << "getIndexAtRow";
      QModelIndex index(row, 0); // not valid constructor..
      return index;
      

      }@

      I would use this code from the main file here :
      @
      void WorkoutCreator::restoreRepeatWidgetInterface()
      {

      foreach (RepeatWidget *wid, lstRepeatWidget)
      {
          int firstRow = wid->firstRow;
          int lastRow = wid->lastRow;
      
          QModelIndex firstIndex =  intervalModel->getIndexAtRow(wid->firstRow);
      
          /// TODO: redraw widget on top of QTableView
      }
      

      }
      @

      Thanks last post for a while sorry for all the posts ;)


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply Reply Quote 0
      • M
        maximus last edited by

        Solved, it was explained in the docs :
        I will try this

        To obtain a model index that refers to an existing item in a model, call QAbstractItemModel::index() with the required row and column values, and the model index of the parent. When referring to top-level items in a model, supply QModelIndex() as the parent index.


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply Reply Quote 0
        • First post
          Last post