Results 1 to 2 of 2

Thread: QTableView spanning bug when moving column to a different visual index

  1. #1
    Join Date
    Sep 2014
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default QTableView spanning bug when moving column to a different visual index

    So in my current project we have a large tableview with many columns, with a hierarchical data structure which we represent by using row spans on items in the table. We also do some custom size calculation to get the table to display at minimum vertical height. That all works great, but we recently discovered that when one of our items spans multiple rows, and is moved to a different position within the table, the cell is not drawn correctly. After pouring through our code base trying to discover where we went wrong, I realized that this bug is evident in even very simple code, which you can see below. You can copy this code into the mainwindow.cpp file in a new Qt Widgets application, and see the bug for yourself. Just run the application, and notice that depending on the size of your window, the column labeled as span will display with no span. Essentially if there is a scrollbar, the cell does not display correctly. If you switch to full-screen the cell displays correctly. You'll also notice that the editor does expand to the correct size.

    Qt Code:
    1. ui->setupUi(this);
    2.  
    3.  
    4. QTableView* tableView = new QTableView;
    5. setCentralWidget(tableView);
    6.  
    7.  
    8. model->setColumnCount(15);
    9. model->setRowCount(10);
    10. model->setHeaderData(0, Qt::Horizontal, "Span");
    11.  
    12. tableView->setModel(model);
    13.  
    14. tableView->setSpan(0,0, 10, 1);
    15.  
    16. tableView->horizontalHeader()->setSectionsMovable(true);
    17.  
    18. tableView->horizontalHeader()->moveSection(0, 8);
    To copy to clipboard, switch view to plain text mode 

    I'm hoping someone can't point out how to fix this the "correct" way because I have a workaround in mind, but I would prefer to understand the problem. I did a few tests in the larger scope of my application where I have custom delegates and such. I found that, when the cell is drawn incorrectly, the QStyleOption argument of the paint method for my delegate has the incorrect size stored in the rect. I can fix this by calling visualRect() on the cell being painted, and the view does return the correct size. However applying that to the drawing rect only makes the cell draw itself correctly, the table grid lines still overlap it as if it has no span. I know I can turn off grid lines, and I'm sure I can find some way to draw the grid lines myself correctly, but it would be nice if I could rely on the built in methods. Also I'm not a fan of calling visualRect() from within my delegate because it means I need to make a pointer to my table view class inside my delegate, or I need to cast the option.widget in the paint method each time and then call visualRect, and I'm concerned about performance because these are rather large tables with lots of HTML rendering.

    Also in my search for a solution I did turn up this bug report, which could be related, it at least sounds like the same issue, and it doesn't seem like it was resolved. It seems crazy to me that this is not a more prevalent problem. Do people not use the span feature that often?

    Anyway, any help that can be offered is appreciated. Thanks for reading.

  2. #2
    Join Date
    Sep 2014
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableView spanning bug when moving column to a different visual index

    Quote Originally Posted by forgottenduck View Post
    I'm hoping someone can't point out how to fix this the "correct" way
    Definitely meant can.

Similar Threads

  1. Has anyone done dynamic column spanning with a QTableWidget?
    By RolandHughes in forum Qt Programming
    Replies: 19
    Last Post: 17th November 2014, 07:47
  2. Replies: 1
    Last Post: 14th September 2010, 17:26
  3. Replies: 2
    Last Post: 5th September 2010, 15:06
  4. How to get current row(column) index in the QTextTable?
    By denny.t in forum Qt Programming
    Replies: 3
    Last Post: 5th April 2006, 08:53
  5. QListView and column moving
    By gadnio in forum Qt Programming
    Replies: 10
    Last Post: 5th January 2006, 18:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.