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. Help changing someone else's code (default window size)
Qt 6.11 is out! See what's new in the release blog

Help changing someone else's code (default window size)

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.4k 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.
  • R Offline
    R Offline
    Rachel_T
    wrote on last edited by
    #1

    First, I must tell you that I am completely new to both Python and QT.
    I recently built a book scanning device according to these instructions. The designer also made image capture software just for this device, which is fine, but they wrote the code on the assumption that a large monitor would be used. Without realizing this, I purchased a 7" Capacitive Touch Screen For Raspberry Pi (1024*600), and when I ran the program, only the upper left corner was visible. When I resize the window, the text and buttons become illegible and unusable. I figured out that the program (which can be found here) uses QT, and furthermore I think I tracked down the culprit to this bit of code in the main file (SimpleBookCapture dot py):

            # メインWindow初期設定
            self.resize(int(1920*3/4), int(1080*3/4))
            self.move(100, 100)
            self.setWindowTitle('Simple Book Capture Ver.0.0.1')
            self.show()
    

    (The Japanese means "Main Window Initial Settings.") I believe there is some way to replace those numbers with percentages of available screen, such as "0.9."
    Then there remains the problem of tweaking how other things get scaled, so that they are legible and useable on my little monitor, but I haven't looked for that code yet.
    Here's a video of me launching the program and resizing the screen. Although the text on the screen is mostly Japanese, you can see by looking at the numbers that the top and bottom of all text gets chopped off a bit, so that "100" looks like "|( )( )."
    This scanner is made to be used at the Kyoto International Manga Museum, and will be used by a number of people besides me. I can't expect them all to learn how to resize the window (which is awkward) and make sense of the cramped results.
    Any guidance would be very much appreciated.

    Pl45m4P 1 Reply Last reply
    0
    • J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      Hi,
      I'm not a python guy, and you didn't tell us what bindings you're using, but I know generally what to look for/turn to in Qt:
      So here's a ChatGPT example. You get the basic premise, but no guarantee this example is actually compiling and running :P

      from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
      from PyQt6.QtGui import QScreen, QFont
      
      class MainWindow(QMainWindow):
          def __init__(self):
              super().__init__()
      
              screen = QApplication.primaryScreen()
              screen_size = screen.size()
              screen_width = screen_size.width()
              screen_height = screen_size.height()
      
              self.resize(int(screen_width * 3 / 4), int(screen_height * 3 / 4))
              self.move((screen_width - self.width()) // 2, (screen_height - self.height()) // 2)
      
              font_size = int(screen_height * 0.02)
              font = QFont("Arial", font_size)
      
              self.setFont(font)
      
      
              label = QLabel("Welcome to Simple Book Capture!", self)
              label.setFont(font)
              label.move(50, 50)
      
      
              self.setWindowTitle('Simple Book Capture Ver.0.0.1')
              self.show()
      
      
      app = QApplication([])
      window = MainWindow()
      app.exec()
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • R Rachel_T

        First, I must tell you that I am completely new to both Python and QT.
        I recently built a book scanning device according to these instructions. The designer also made image capture software just for this device, which is fine, but they wrote the code on the assumption that a large monitor would be used. Without realizing this, I purchased a 7" Capacitive Touch Screen For Raspberry Pi (1024*600), and when I ran the program, only the upper left corner was visible. When I resize the window, the text and buttons become illegible and unusable. I figured out that the program (which can be found here) uses QT, and furthermore I think I tracked down the culprit to this bit of code in the main file (SimpleBookCapture dot py):

                # メインWindow初期設定
                self.resize(int(1920*3/4), int(1080*3/4))
                self.move(100, 100)
                self.setWindowTitle('Simple Book Capture Ver.0.0.1')
                self.show()
        

        (The Japanese means "Main Window Initial Settings.") I believe there is some way to replace those numbers with percentages of available screen, such as "0.9."
        Then there remains the problem of tweaking how other things get scaled, so that they are legible and useable on my little monitor, but I haven't looked for that code yet.
        Here's a video of me launching the program and resizing the screen. Although the text on the screen is mostly Japanese, you can see by looking at the numbers that the top and bottom of all text gets chopped off a bit, so that "100" looks like "|( )( )."
        This scanner is made to be used at the Kyoto International Manga Museum, and will be used by a number of people besides me. I can't expect them all to learn how to resize the window (which is awkward) and make sense of the cramped results.
        Any guidance would be very much appreciated.

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

        Hi and welcome to the forum :)

        I've read bits of the original code and couldn't find anything suspicious.
        So even when you resize the window manually, the result is not satisfying or what you expect?
        In your video it looks like some comboBoxes (the elements the with a drop-down menu) are not displayed correctly?!

        @Rachel_T said in Help changing someone else's code (default window size):

        I believe there is some way to replace those numbers with percentages of available screen, such as "0.9."
        Then there remains the problem of tweaking how other things get scaled, so that they are legible and useable on my little monitor

        Yes it should be possible, in fact the actual code already uses some kind of scaling, because as you can see

        self.resize(int( 1920*3/4 ), int( 1080*3/4) )
        

        it uses 3/4 of 1920x1080 (which equals the size of FullHD resolution). I assume it's due to some scaling of their original screen.

        Ah, while I am typing this, I see @J-Hilk has replied.

        You can use code like he posted above to get your current screen size

        (This part here)

        screen = QApplication.primaryScreen()
        screen_size = screen.size()
        screen_width = screen_size.width()
        screen_height = screen_size.height()
        
        # this does not need to be 3/4...
        # play around with different sizes until you get what you want
        self.resize(int(screen_width * 3 / 4), int(screen_height * 3 / 4))
        
        # this is where the window appears on your screen.
        # topleft corner is the origin of the coordinate system ( 0 / 0 )
        self.move((screen_width - self.width()) / 2, (screen_height - self.height()) / 2)
        

        or you try one of

         self.showFullScreen()
        

        or

          self.showMaximized()
        

        instead of just self.show()

        But I don't know for sure whether it will work (and set the correct size) on PyQt and your Raspberry.

        Edit:

        @J-Hilk The original code says PyQt5... Can't tell if there are possible issues with scaling and screen sizes (:
        Could not find any trace of something around HighDPIScaling or so...


        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
        0
        • R Offline
          R Offline
          Rachel_T
          wrote on last edited by
          #4

          Thanks to both of you for your responses! Deleting the "resize" line and changing "self.show" to "self.showMaximized" did the trick. Now I just need to see what I can do to make it all more legible.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rachel_T
            wrote on last edited by Rachel_T
            #5

            There are items in this main window that I don't need and can't use anyway, and I found those components in a script named "CameraSettingsPage dot py."
            I was able to delete the "Save RAW and Meta data" item easily, so I saved a whole line of space there, but when I deleted code for the "Sensor mode" (which also seems to be unusable)...

                    # センサモードのコンボボックス
                            self.sensorFormat = QComboBox()
                            #self.sensorFormat.addItem("Default")
                            self.sensorFormat.addItems([f'{x["formatfsensor"].format} {x["size"]}' for x in picam2s[camid].sensor_modes])
                            # 最大の解像度(4608x2592)に設定
                            # プレビューとキャプチャの画角違い防止のため固定
                            self.sensorFormat.setCurrentIndex(2)
                            self.sensorFormat.setEnabled(False)
                            formLayout.addRow("センサーモード", self.sensorFormat)
            

            ...the program would no longer launch. I assume there are references to things in this code elsewhere in this script (or maybe other scripts) that I would also need to delete or modify.
            I also would like to get rid of the "Image Size" (画像サイズ) item just below the sensor mode item.

                    # 画像サイズ反映ボタン
                    self.resButton = QPushButton("反映")
                    self.resButton.setEnabled(False)
                    # 画像サイズ反映ボタンクリック時の動作
                    self.resButton.clicked.connect(self.on_resButton_clicked)
                    
                    # 画像の縦横サイズを変更時は反映ボタンを有効化
                    self.imageWidth.valueChanged.connect(lambda: self.resButton.setEnabled(True))
                    self.imageHeight.valueChanged.connect(lambda: self.resButton.setEnabled(True))
                    
                    # 画像サイズ
                    resolution = QWidget()
                    resHLayout = QHBoxLayout()
                    resolution.setLayout(resHLayout)
                    resHLayout.addWidget(self.imageWidth)
                    resHLayout.addWidget(QLabel("x"), alignment=Qt.AlignHCenter)
                    resHLayout.addWidget(self.imageHeight)
                    resHLayout.addWidget(QLabel(" "), alignment=Qt.AlignHCenter)
                    resHLayout.addWidget(self.resButton)
                    formLayout.addRow("画像サイズ", resolution)
            

            Getting rid of those two would make this window plenty usable and legible. (As it is, the "Rotation" control, just below the "Image size" control, is unusable with the window sized to fit my screen, because the button isn't visible.)

            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