Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTableWidget how to get number of rows in each cell



  • Hi,

    i created a table with a given number of rows and columns. I also used setSpan() to merge some cells together.

    Now i need to retrieve the number of rows and columns in each cell after merging. Is there a method to loop through all merged cells to get the data I want?

    I thought of using rowCount() and columnCount() but it only works with the whole table.

    Thank you all



  • @dzungng
    You have to march through the cells of the table reading their QTableView::column/rowSpan(int row, int column) to calculate what is there including spanning.



  • Thank you for your answer.
    I created a table using QTableWidget. Can I use the function you recommended for QTableWidget?



  • @dzungng
    QTableWidget inherits from QTableView. That means all QTableView methods are also available on a QTableWidget. This principle is worth understanding, as it applies all over the place with QWidgets (and other Qt derived classes).


Log in to reply