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. get selected single cell in QTextTable?
Qt 6.11 is out! See what's new in the release blog

get selected single cell in QTextTable?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 660 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.
  • M Offline
    M Offline
    mondayboy
    wrote on last edited by
    #1

    hi,I know selectedTableCells() can get multiple cells in QTextTable, but how can I get selected single cell in QTextTable?

    JonBJ 1 Reply Last reply
    0
    • M mondayboy

      @JonB said in get selected single cell in QTextTable?:

      selectedTableCells

      hi, selectedTableCells() is a public funtion of QTextCursor Class. When my selection spans over table cells, it works, but when I just select one single cell, it returns (-1,-1,-1,-1), not row index and column index of the cell.

      B Offline
      B Offline
      Bob64
      wrote on last edited by
      #4

      @mondayboy I'm not familiar with this, but I took a look at the doc and it seems to be consistent with the behaviour you describe.

      Could you use this in the single cell case:

      QTextTableCell QTextTable::cellAt(const QTextCursor &cursor) const

      ?

      M 1 Reply Last reply
      1
      • M mondayboy

        hi,I know selectedTableCells() can get multiple cells in QTextTable, but how can I get selected single cell in QTextTable?

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

        @mondayboy
        Your question is unclear. What Qt function is the selectedTableCells() which you say you know to use? If whatever it is returns all selected cells, and the user only selects a single cell, then that will be the first and only element in the returned list.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mondayboy
          wrote on last edited by
          #3

          @JonB said in get selected single cell in QTextTable?:

          selectedTableCells

          hi, selectedTableCells() is a public funtion of QTextCursor Class. When my selection spans over table cells, it works, but when I just select one single cell, it returns (-1,-1,-1,-1), not row index and column index of the cell.

          B JonBJ 2 Replies Last reply
          0
          • M mondayboy

            @JonB said in get selected single cell in QTextTable?:

            selectedTableCells

            hi, selectedTableCells() is a public funtion of QTextCursor Class. When my selection spans over table cells, it works, but when I just select one single cell, it returns (-1,-1,-1,-1), not row index and column index of the cell.

            B Offline
            B Offline
            Bob64
            wrote on last edited by
            #4

            @mondayboy I'm not familiar with this, but I took a look at the doc and it seems to be consistent with the behaviour you describe.

            Could you use this in the single cell case:

            QTextTableCell QTextTable::cellAt(const QTextCursor &cursor) const

            ?

            M 1 Reply Last reply
            1
            • M mondayboy

              @JonB said in get selected single cell in QTextTable?:

              selectedTableCells

              hi, selectedTableCells() is a public funtion of QTextCursor Class. When my selection spans over table cells, it works, but when I just select one single cell, it returns (-1,-1,-1,-1), not row index and column index of the cell.

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

              @mondayboy
              Thanks. Interesting. Googling qt selectedtablecells does not supply any hit for such a function, under QTextCursor or anywhere else. I rely on this to locate functions, it has let me down this time!

              The documentation is a bit unclear, but it looks like it only returns anything if the selection spans over multiple table cells, which is a bit weird.

              I see @Bob64 has posted a suggestion while I was typing, try that.

              M 1 Reply Last reply
              0
              • B Bob64

                @mondayboy I'm not familiar with this, but I took a look at the doc and it seems to be consistent with the behaviour you describe.

                Could you use this in the single cell case:

                QTextTableCell QTextTable::cellAt(const QTextCursor &cursor) const

                ?

                M Offline
                M Offline
                mondayboy
                wrote on last edited by
                #6

                @Bob64 Thank you very much Bob! It works. In pyqt, I writed like this:

                ...
                text_cursor = self.textCursor()
                print(qtexttable.cellAt(text_cursor).row())
                print(qtexttable.cellAt(text_cursor).column())
                ....
                

                and it returned my wanted answer.

                1 Reply Last reply
                0
                • JonBJ JonB

                  @mondayboy
                  Thanks. Interesting. Googling qt selectedtablecells does not supply any hit for such a function, under QTextCursor or anywhere else. I rely on this to locate functions, it has let me down this time!

                  The documentation is a bit unclear, but it looks like it only returns anything if the selection spans over multiple table cells, which is a bit weird.

                  I see @Bob64 has posted a suggestion while I was typing, try that.

                  M Offline
                  M Offline
                  mondayboy
                  wrote on last edited by mondayboy
                  #7

                  @JonB Yes, JonB, Bob64's answer is right. I get QTextTableCell using QTextTabl..cellAt(textCursor), and get row and col index using .row() and .colunm() function.

                  1 Reply Last reply
                  0
                  • M mondayboy has marked this topic as solved on

                  • Login

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