Getting Scene and View Sizes Down



  • Hi everyone,

    I'm a little bit confused on how I set up View and Scene sizes in comparison to eachother.

    What I'm trying to achieve is a QGraphicsView main widget with a QGraphicsScene that spawns a QWebView that overlays the graphics view with 3/4 of its width, and all of its height. However, when I resize the QGraphicsView using showMaximized(), it doesn't look like it's actually updating the size, even though it appears maximized. Here's what I'm doing:

    @graphicsView->showMaximized(); //maximize the graphics scene so the window is maximized@

    @graphicsScene->setSceneRect(QRect(QPoint(0, 0), QPoint(graphicsView->width(), graphicsView->height()))); //make the scene fill up the graphics view@

    @graphicsView->setScene(graphicsScene);@

    At this point, the graphicsView object says that it is 256x192 using width() and height().
    However, it's obviously maximized and definitely bigger than that. If these numbers were accurate, then I'd like to create my QWebView, and set it to be 3/4 the width of the graphics view, and 100% of the height, centered.

    Any idea on where I'm going wrong? This is my first time at Qt so it's probably something stupid :)



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.