Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Get maximized window size when maximized?
Forum Updated to NodeBB v4.3 + New Features

Get maximized window size when maximized?

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 3 Posters 4.3k 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.
  • P Offline
    P Offline
    PhantomzBack
    wrote on 1 Sept 2021, 16:37 last edited by
    #1

    I want to get the size of my QT Main Window or QT Label, since I am trying to make a full screen image viewer. The image management would be done in OpenCV and the GUI will be QT based. I need to resize the image to fit the viewer in OpenCV itself. Here is my code at present.

    # importing libraries
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import *
    from PyQt5.QtCore import *
    import sys
    
    width, height=0,0
    
    class Window(QMainWindow):
        def __init__(self):
            super().__init__()
    
            # setting title
            self.setWindowTitle("WhiteCam Viewer")
    
            # setting geometry
            self.setGeometry(100, 100, 600, 400)
    
            # calling method
            self.UiComponents()
    
            # showing all the widgets
            self.show()
    
        # method for widgets
        def UiComponents(self):
            global width, height
            self.showFullScreen()
            self.imageLabel=QLabel("cooool",self)
            self.setCentralWidget(self.imageLabel)
            self.imageLabel.setStyleSheet("background-color: #FF0000")
            width=window.imageLabel.geometry().width()
            height=window.imageLabel.geometry().height()
            print(width, height)
            
            
    # create pyqt5 app
    App = QApplication(sys.argv)
    
    # create the instance of our Window
    window = Window()
    
    
    # start the app
    sys.exit(App.exec())
    

    The width and height are returned as 100, 30 when the expectation is 1920,1080

    632da661-add9-4489-ae4c-a3fc48a446f5-image.png
    as can be seen from this image. How can I do so?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeCFD
      wrote on 1 Sept 2021, 17:10 last edited by
      #2

      you need something like the following:
      QRect rec = QGuiApplication::screens().at( 0 )->geometry();
      auto fullscreen_size = QSize( rec.width(), rec.height() );

      1 Reply Last reply
      1
      • P Offline
        P Offline
        PhantomzBack
        wrote on 1 Sept 2021, 17:39 last edited by PhantomzBack 9 Jan 2021, 17:43
        #3

        @JoeCFD
        Thanks!
        What about a maximized window? I modified the code to be Fullscreen just to test if it gave the results I wanted.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 1 Sept 2021, 17:52 last edited by
          #4

          Hi and welcome to devnet,

          Widgets do not have their final dimensions until they are shown hence your issue.

          You can use the showEvent method to load the image in its final size. Since you are writing some sort of viewer, you should rather have a slot manage that part. For your current test, you can call it using a single shot timer with a time of 0.

          On a side note, calling show or showFullScreen from within the constructor is a bad habit. Widget shall not show themselves, it's the responsibility of the method or class managing the widget to show it at the right time which may or may not be after construction.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          1/4

          1 Sept 2021, 16:37

          • Login

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