Getting Scene and View Sizes Down
-
Update: So I figured out that when I call showMaximized(), it's just sending a signal for the resize and doesn't actually do it. If I place everything else on a single QTimer, it works and gets the right dimensions.
So here's my question: is there a way to call a slot after the showMaximized() goes through? Would overriding resizeEvent() and searching for a maximization event work? If so, how would I do that?
-
You could try calling a slot via the event queue. The way to do that is to use QMetaObject::invokeMethod, and explicitly specify the connection type Qt::QueuedConnection as second parameter.
-
Thanks Asperamanca,
The invokeMethod method just confused the heck out of me. Do you know of any examples where this is used that I can look at for reference?
-
Quick question, are you trying to do this in your constructor code? If so, try moving the resize to the virtual showEvent(QShowEvent *) in the class.
-
dvez43, I tried putting stuff inside showEvent(), but it doesn't seem to run when maximized.
@void MyMainWindow::showEvent(QShowEvent *) {
qDebug() << "Main window size: " << this->width() << "x" << this->height();
}@I'm getting an output of 200x100, so I'm assuming this is not called after the resize takes place. In my constructor I have:
@MyMainWindow::MyMainWindow(QWidget *parent) :
QMainWindow(parent) {
this->setWindowState(Qt::WindowMaximized);
this->show();
....
}
@ -
@bool bOk = QMetaObject::invokeMethod(this,"dataChanged",Qt::QueuedConnection,
Q_ARG(bool,true));
@That should call a slot named "dataChanged" which accepts a single bool parameter.
The return value tells you whether the slot exists and matches in parameters. Like the return value of 'connect' -
Asperamanca, I'm still getting a size of 200x100 when the init() function runs:
@MyMainWindow::MyMainWindow(QWidget *parent) :
QMainWindow(parent) {
this->setWindowState(Qt::WindowMaximized);
this->show();
bool qOk = QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection, Q_ARG(bool, true));
}void MyMainWindow::init(bool pSuccess) {
qDebug() << "Main window size: " << this->width() << "x" << this->height();
...
}@Am I used the invokeMethod incorrectly?
-
The bool parameter doesn't seem to make sense (from the name it sounds like a return parameter, which wouldn't work for a queued connection).
But otherwise, the code should execute the slot.
Can you check whether the widget is already maximized in this slot? this->maximized() should do the trick.
-
Yes, this->isMaximized() returns true. It just seems like the width and height aren't being updated.
-
I'm still stuck on this. Is some signal emitted when the view is resized that I can latch onto or something?