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. QOpenGLWidget gives incorrect h & w values.
Forum Updated to NodeBB v4.3 + New Features

QOpenGLWidget gives incorrect h & w values.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 293 Views 2 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.
  • S Offline
    S Offline
    SilentBatv-2
    wrote on last edited by
    #1

    In QOpenGLWidget are there any cases where the resize function doesn't has incorrect parameters for w and h? as u can c my QOpenglWidget has a resize params of 22 and 182, which are beyond obviously incorrect for a full screen application, the aspect ratio from snipping tool tells to be roughly 2.25Screenshot (31).png Screenshot (32).png
    And its not the install it seems because I have another project which seems to give valid values in the resizeGL function.

    Nodes::Nodes(QWidget *parent)
        : QMainWindow(parent)
    {
        setupMenuBar();
        setupStatusBar();
        setupCentralWidget();
    }
    
    void Nodes::setupCentralWidget()
    {
        
        centre = new QWidget();
    
        QVBoxLayout* centralLayout = new QVBoxLayout();
    
        tabBar = new QTabBar();
        renderer = new Renderer();
    
        centralLayout->addWidget(tabBar);
        centralLayout->addWidget(renderer);
    
    
        centre->setLayout(centralLayout);
    
        setCentralWidget(centre);
        
        //setCentralWidget(new Renderer());
    }
    
    

    here is the declaration of the widget which returns the invalid values

    Melon::Melon(QWidget* parent)
        : QMainWindow(parent), propertyPanelDisplayed(false), window(new Preferences_Window(nullptr))
    {
        setupStatusBar();
        setupMenuBar();
        setupToolBar();
        setupworld();
        setupDockWidget();
        setupPropertyTab();
        setupInputPanel();
    
        displayPropertyTab();
    
    }
    void Melon::setupworld()
    {
        setCentralWidget(new Renderer(this));
    }
    

    meanwhile this is the declaration of the widget which returns the size values correctly, Although im unsure predefination is the cause given the resize function is called at the app.show() function anyways so by then all the initialization regardless of order should be done, and I feel I have defined both the widgets correctly here
    I have tried quite a bit to figure out what is wrong here, given I couldnt i am beginning to think maybe this is a bug which might need reporting but honestly im not sure. Thanks for the help in advacnce.

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Two things here: 2.25 is a common High DPI scaling factor on Windows. You have to configure your app appropriately to take the scaling into consideration or get the absolute unscaled device sizes. See here.
      Second thing, the size of 22x182 suggest you are getting a minimum window size (considering the title bar decorations), which is what you get before the underlying native surface is created. Querying it directly after show() is too soon. Native surface creation is deferred and any size query before the first showEvent() is not valid and will give you that placeholder value.

      1 Reply Last reply
      3
      • S Offline
        S Offline
        SilentBatv-2
        wrote on last edited by
        #3

        I mean I am not querying it explicitly, The resizeGL() function is never called explicitly and is always called by the Qt framework. Me saying that it is called after app.show() was because a friend of mine suggested that maybe this is because of improper initialization order on my end. That was just an argument to prove otherwise. Also It is true that the 182, 22 are placeholder values since the show and show maximized dont seem to make a difference but i couldnt understand what u meant by native surface creation, if u dont mind can u explain a bit in detail or link any resource for it? thanks

        Pl45m4P 1 Reply Last reply
        0
        • S SilentBatv-2

          I mean I am not querying it explicitly, The resizeGL() function is never called explicitly and is always called by the Qt framework. Me saying that it is called after app.show() was because a friend of mine suggested that maybe this is because of improper initialization order on my end. That was just an argument to prove otherwise. Also It is true that the 182, 22 are placeholder values since the show and show maximized dont seem to make a difference but i couldnt understand what u meant by native surface creation, if u dont mind can u explain a bit in detail or link any resource for it? thanks

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @SilentBatv-2 said in QOpenGLWidget gives incorrect h & w values.:

          what u meant by native surface creation, if u dont mind can u explain a bit in detail or link any resource for it? thanks

          The moment you call show() on a widget, it's about to show but not rendered properly (including all layouts and parent/child relations).
          So the native surface where your widget is drawn is not fully initialized.

          To get any geometry after the widget is shown on the screen and respecting layouts etc. use the QWidget's showEvent(). Call your function from there and you will get the values which match with what you actually see on your screen.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          1
          • Chris KawaC Online
            Chris KawaC Online
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            i couldnt understand what u meant by native surface creation

            Both Qt and OpenGL draw to OS provided surfaces e.g. a window identified by a window handle (HWND). Because of reasons I won't get into here your main window and QOpenGLWidget don't share that resource but create one for each and composite them over one other (well, not necessarily true, but lets keep it simple). Creating those underlying surfaces is relatively costly (in terms of memory consumption, system resources and speed), so when you create a widget it doesn't immediately allocate them. It is deferred to the moment a widget is actually made visible. Until that time a geometry of a widget is unspecified. You can explicitly call e.g. setGeometry or resize, which do record a desired size, but that still doesn't allocate the native surface until the widget is made visible.

            I mean I am not querying it explicitly, The resizeGL() function is never called explicitly and is always called by the Qt framework

            Both code snippets you've shown set up the widgets in the main window constructor, so they are shown at the same time and there is only one call to resizeGL from the show() call of MainWindow. That shouldn't exhibit the behavior you describe, so there must be something else you're doing and not showing here. In your callstack window right click anywhere and from the context menu tell it to show external code. It will show you what in your main() is calling resizeGL.

            1 Reply Last reply
            1

            • Login

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