Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting Scene and View Sizes Down
Qt 6.11 is out! See what's new in the release blog

Getting Scene and View Sizes Down

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 7.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kbarresi
    wrote on last edited by
    #1

    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 :)

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kbarresi
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kbarresi
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vezprog
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kbarresi
              wrote on last edited by
              #6

              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();
              ....
              }
              @

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                @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'

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kbarresi
                  wrote on last edited by
                  #8

                  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?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Asperamanca
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kbarresi
                      wrote on last edited by
                      #10

                      Yes, this->isMaximized() returns true. It just seems like the width and height aren't being updated.

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kbarresi
                        wrote on last edited by
                        #11

                        I'm still stuck on this. Is some signal emitted when the view is resized that I can latch onto or something?

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved