PDA

View Full Version : QTableView: strange behavior on a window maximization. How to fix that?



sarbash
25th June 2010, 14:02
Hello all.

Seems like a bug...

in constructor:


ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
ui->tableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
ui->tableView->resizeColumnsToContents();
ui->tableView->resizeRowsToContents();

connect(ui->tableView->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
ui->tableView, SLOT(resizeRowsToContents()));


It's ok with that if you minimize the window/restore the state of the window.
But when window is maximizing QTableView's row heights stay unaffected by event. Just ignore maximization...
One strange thing: after maximization, row heights seem like resized for a normal window state. After returning from maximized state to normal, row heights seem like resized for a maximized window state, i.e. in other words resizing is looks like working with a latency equally to the previous window state. Seems like row height's resizing happens for the old WindowState, just before window became into the new state.
Just one window's minimization repairs the situation but, till another maximization...
Any workaround?
Thanks.

---
Qt 4.6.2
WinXP SP2 Rus
Qt SDK 2010.01

sarbash
29th June 2010, 12:03
okay, I've made a crutch by helping of a signal to workaround the window's maximization problem and posted the bug.

SixDegrees
29th June 2010, 12:55
Changing geometry inside a constructor isn't recommended. The objects involved may not be fully constructed yet, while the layout managers require them to be in order to perform their job. It's normally better to perform this sort of task after the constructor is finished; the polish() routine may be of help here, or you can simply insert the resizing code somewhere after object construction in your own code.

sarbash
29th June 2010, 18:04
Agreed with you.
But if you noticed that, constructor mainly was used for setting appropriate parameters. Sizing methods were applied to already prepared widgets (notice that setupUi() in the beginning). The problem is with reaction to window's maximization.
But, it's ok now. I changed implementation because I've noticed significant performance degradation caused by
setResizeMode(QHeaderView::ResizeToContents) parameter.
So, I've maded an appropriate signal and emit it in
QMainWindow::changeEvent(QEvent *) when necessary.
Thank you for the participation.