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. QTableView/QTableWidget Cell Span Range
Forum Updated to NodeBB v4.3 + New Features

QTableView/QTableWidget Cell Span Range

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 3.3k 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.
  • A Offline
    A Offline
    Adam Crowe
    wrote on last edited by
    #1

    Hello,

    Is there a way to get the range of a spanned cell from any position within the spanned cell?

    For example, I can use QTableView::rowSpan(1, 1) and QTableView::columnSpan(1, 1) to find that the cell with "B" in it has a span of 2x2; but how can I find the beginning of the spanned range if I query cell at row 2 and column 2 (the bottom right corner of cell "B")? I need a way to get back (row 1, column 1) from it.

    alt text

    Thank you!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I think it should be possible through QTableView::rowSpan() and QTableView::columnSpan()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Adam Crowe
        wrote on last edited by
        #3

        Thank you @Christian-Ehrlicher. Unfortunately, all QTableView::rowSpan() and QTableView::columnSpan() tells me is what the total span is, but it doesn't tell me which cell it starts at, so if I had a span of 3x3 and I checked the rowSpan and colSpan of the middle cell, it would tell me 3 and 3.

        JonBJ 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          From looking a little bit at the sources you have to remember it by youself. No chance to get it out of the QTableView

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • A Adam Crowe

            Thank you @Christian-Ehrlicher. Unfortunately, all QTableView::rowSpan() and QTableView::columnSpan() tells me is what the total span is, but it doesn't tell me which cell it starts at, so if I had a span of 3x3 and I checked the rowSpan and colSpan of the middle cell, it would tell me 3 and 3.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Adam-Crowe
            I don't see there is a quicker way than: you must iterate through the columns/rows (left-to-right/top-to-bottom) looking at the current value of row/columnSpan() in each cell. From that you can obviously calculate where a given cell coordinate really lies in your terms.

            @Christian-Ehrlicher : You say "No chance to get it out of the QTableView". I agree there is not a simple call to return this, but I say you can calculate it in loops. Have I said anything incorrect here?

            1 Reply Last reply
            1
            • A Offline
              A Offline
              Adam Crowe
              wrote on last edited by
              #6

              Thank you everybody,

              I wrote this little thing just now and it seems to work:

              struct Coordinates { int row; int col; };
              
              Coordinates getFirstCellInSpan(const int &row, const int &col)
              {
                  Coordinates xy;
              
                  int firstRow = 0;
                  int firstCol = 0;
              
                  while (firstRow + rowSpan(firstRow, col) <= row)
                  {
                      firstRow++;
                  }
              
                  while (firstCol + columnSpan(firstRow, firstCol) <= col)
                  {
                      firstCol++;
                  }
              
                  xy.row = firstRow;
                  xy.col = firstCol;
              
                  return xy;
              }
              
              JonBJ 1 Reply Last reply
              1
              • A Adam Crowe

                Thank you everybody,

                I wrote this little thing just now and it seems to work:

                struct Coordinates { int row; int col; };
                
                Coordinates getFirstCellInSpan(const int &row, const int &col)
                {
                    Coordinates xy;
                
                    int firstRow = 0;
                    int firstCol = 0;
                
                    while (firstRow + rowSpan(firstRow, col) <= row)
                    {
                        firstRow++;
                    }
                
                    while (firstCol + columnSpan(firstRow, firstCol) <= col)
                    {
                        firstCol++;
                    }
                
                    xy.row = firstRow;
                    xy.col = firstCol;
                
                    return xy;
                }
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Adam-Crowe
                Exactly, as I said you have to iterate to find out, just as you have done :) Qt could have provided such a function, but it does not, and I don't know that internally it saves the data in any way which would be quicker than this; and even if it does, there is no public API for you to access that, other than what you have done.

                1 Reply Last reply
                0
                • M mpergand referenced this topic on

                • Login

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