CDialog OnInitDialog()
-
I'm porting a lot a MFC code to Qt right now.
Most of the CDialog derived dialogues don't initialise everything in the ctor. MFC programmers often construct the dialogues, then maybe invoke a few methods to configure this or that and then call (e.g.) DoModal() to display the dialogue. At this point (just before the dialogue is displayed), the OnInitDialog() method is invoked:
"Override this method if you want to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but ignore its return value. You will typically return TRUE from your overridden method."
Is there a method/slot in QDialog that I can override that is called immediately before the dialogue is displayed using e.g. show() or exec()?
Thanks
David -
-
@JonB I do this code:
void LocationDlg::showEvent(QShowEvent* event) { QSize sizeOfTableView = tableView->size(); QSize sizeOfWindow = this->size(); resize(sizeOfTableView.width(), sizeOfWindow.height()); QDialog::showEvent(event); }
But the window is not the width of the QTableView!!!
See?
-
@jdent said in CDialog OnInitDialog():
See?
Not really, no. Window looks to be the width of the table view to me.
If you mean you think the table view is first going to be full-width (so no horizontal scroll) and then the dialog will resize its width to that I would not expect that behaviour,
Did you try debugging out the size values?
Other than that I might try putting the base call
QDialog::showEvent(event);
before rather than after thesize()
calls as that might influence their values? -
@JonB No I switched to:
void LocationDlg::showEvent(QShowEvent* event) { QDialog::showEvent(event); QSize sizeOfTableView = tableView->size(); QSize sizeOfWindow = this->size(); resize(sizeOfTableView.width(), sizeOfWindow.height()); }
but the size of the table view is less than that of the window.....
I need the full size of the table view as in the sum of the widths of its columns... -
@jdent
You show a screenshot where so far as I can see the table view fills the width of the dialog. So you may know what else you mean, and perhaps someone else will, but I do not.I now see you have created https://forum.qt.io/topic/155541/how-do-i-iterate-across-the-columns-of-a-qtableview-so-i-can-find-the-total-width-of-the-table. I assume that is now the question you wish to ask. It would nice if you took the time to cross-reference from that question to this and vice versa so that people knew and did not spend time trying to answer both....