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. How to get the cell coordinates in QTableView
Qt 6.11 is out! See what's new in the release blog

How to get the cell coordinates in QTableView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.7k 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hi All

    I have created a TableView and on the click i want to get coordinates of the cell in which user has clicked and
    create a combobox in that cell & combobox should fix exactly in that cell.How to do this?

    Here is my code
    @
    QStandardItem* item1 = new QStandardItem("Test1");
    QStandardItem* item2 = new QStandardItem("Test2");

    Note: tablemodel_PT is of type QStandardItemModel*.
    tablemodel_PT->insertRow(1 );
    tablemodel_CA->setItem( row, 0, item1 );
    tablemodel_CA->setItem( row, 1, item2 );
    QComboBox* combo_PT = new QComboBox();
    Note:tableView_PT is the object name of the TableView
    QPoint point( 5 + ui.tableView_PT->columnViewportPosition ( col ) , ui.tableView_PT->rowViewportPosition(row) );
    combo_PT->move( ui.tableView_PT->mapToGlobal(point) );
    combo_PT->show();
    @

    @
    with above code when I am clicking in any of the cell the combobox is created but it is not place exactly in the cell in which it is clicked it is overlapping with adjacent cells.@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Don't do it that way. Instead, use a delegate that manages the combo box. There are examples in the documentation and on the forum.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Indrajeet
        wrote on last edited by
        #3

        Hi Andre

        Can you please give me the link of the example in documentation.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          khrl01
          wrote on last edited by
          #4

          Maybe You take a look at
          http://developer.qt.nokia.com/wiki/Combo_Boxes_in_Item_Views

          regards
          karl-heinz

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            These are relevant:

            "Sections on delegate classes":http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html#delegate-classes

            Spinbox delegate "example":http://developer.qt.nokia.com/doc/qt-4.8/itemviews-spinboxdelegate.html

            Color delegate factory "example":http://developer.qt.nokia.com/doc/qt-4.8/itemviews-coloreditorfactory.html

            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 Extensions
            • Unsolved