Hi,
I have a QTableView in my applications main window, and need to set its column widths to a certain % of the window size and it needs to be done when the application first opens, the window opens maximized.
So in my constructor I do this,
// Initial queue column width %s
int width = desk->geometry().width() - 20; // - overheads
ui->tbQueueView->horizontalHeader()->resizeSection(0, (width / 100) * 64);
ui->tbQueueView->horizontalHeader()->resizeSection(1, (width / 100) * 7);
ui->tbQueueView->horizontalHeader()->resizeSection(2, (width / 100) * 15);
ui->tbQueueView->horizontalHeader()->resizeSection(3, (width / 100) * 5);
ui->tbQueueView->horizontalHeader()->resizeSection(4, (width / 100) * 9);
// Initial queue column width %s
QDesktopWidget* desk = QApplication::desktop();
int width = desk->geometry().width() - 20; // - overheads
ui->tbQueueView->horizontalHeader()->resizeSection(0, (width / 100) * 64);
ui->tbQueueView->horizontalHeader()->resizeSection(1, (width / 100) * 7);
ui->tbQueueView->horizontalHeader()->resizeSection(2, (width / 100) * 15);
ui->tbQueueView->horizontalHeader()->resizeSection(3, (width / 100) * 5);
ui->tbQueueView->horizontalHeader()->resizeSection(4, (width / 100) * 9);
To copy to clipboard, switch view to plain text mode
This works, but If I have dual monitors it obviously doesn't because its greater than the size of a maximized application window.
Is there a better approach? Ideally I would know the actual window size here and do %s of that, but because the window hasn't been drawn in the constructor I don't think I can find that out? Additionally I don't think there's a signal that I can use as soon as the window is drawn.
Anyone know a good approach?
Thanks,
Jack
Bookmarks