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. Design of window with PyQt 5
Forum Updated to NodeBB v4.3 + New Features

Design of window with PyQt 5

Scheduled Pinned Locked Moved Unsolved Qt for Python
15 Posts 5 Posters 2.6k 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
    Samuel Bachorik
    wrote on 17 Apr 2020, 17:46 last edited by
    #1

    Hello dear users iam using PyQt5 and i noticed all my programs looks old. They have old looking design like this

    c83ac3e8-cffb-4fa3-9f52-7568f64df0a5-image.png

    But how to make mine programs looks like this one

    pyqt-download-progress-bar-tutorial.png

    Thank you a lot for your help !

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Apr 2020, 18:03 last edited by
      #2

      Hi,

      What version of PyQt5 are you using ?
      What version of Windows are you running ?
      How are you starting your application ?
      Can you share a minimal reproducible example that shows this ?

      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
      0
      • S Offline
        S Offline
        Samuel Bachorik
        wrote on 17 Apr 2020, 18:21 last edited by
        #3

        class Window(QMainWindow):

        def init(self):
        super().init()

           self.setGeometry(300, 300, 400, 500)
           self.setWindowTitle("Please login")
        

        this is how i start program.
        iam using windows 10 and PyQt5 5.14.12

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 17 Apr 2020, 18:25 last edited by
          #4

          Hi,

          No this is not. This is just a class declaration.
          It would be best to provide all the code that allows to start you application properly.

          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
          0
          • S Offline
            S Offline
            Samuel Bachorik
            wrote on 17 Apr 2020, 18:44 last edited by
            #5

            Like this iam sorry

            from PyQt5 import QtWidgets
            from PyQt5.QtWidgets import QMainWindow
            import sys
            from PyQt5.QtWidgets import QApplication

            class Window(QMainWindow):

            def __init__(self):
                super().__init__()
            
                self.name = ""
                self.password = ""
            
                self.setGeometry(300, 300, 400, 500)
                self.setWindowTitle("Hello")
            
                self.b1 = QtWidgets.QPushButton(self)
                self.b1.setText("Button")
                self.b1.move(120, 155)
                self.b1.resize(170, 32)
                self.show()
            

            if name == "main":
            app = QApplication(sys.argv)
            window = Window()
            sys.exit(app.exec())

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Volodymyr14
              wrote on 17 Apr 2020, 18:55 last edited by
              #6

              Don`t do these setGeometry!

              class Window(QMainWindow):
                  
                  def __init__(self, parent=None):
                      super(Window, self).__init__(parent)
                      self.setWindowTitle("Please login")
              
              if __name__ == "__main__":
                  ...
                  app_window = Window()
                  app_window.show()
                  desktop = QtWidgets.QApplication.desktop()
                  resolution = desktop.availableGeometry()
                  app_window.setFixedWidth(resolution.width() / 2)
                  app_window.setFixedHeight(resolution.height() / 2)
                  app_window.move(resolution.center() - app_window.rect().center())
                  sys.exit(app.exec_())
              

              PyQt/PySide

              1 Reply Last reply
              2
              • V Offline
                V Offline
                Volodymyr14
                wrote on 17 Apr 2020, 19:31 last edited by
                #7

                Or if want to save stretch:

                class Window(QMainWindow):
                
                    def __init__(self, parent=None):
                        super(Window, self).__init__(parent)
                        self.setWindowTitle("Please login")
                        self.setMinimumWidth(resolution.width() / 2)
                        self.setMinimumHeight(resolution.height() / 2)
                        ...
                
                
                if __name__ == "__main__":
                    ...
                    app = QtWidgets.QApplication(sys.argv)
                    desktop = QtWidgets.QApplication.desktop()
                    resolution = desktop.availableGeometry()
                    app_window = Window()
                    app_window.show()
                    app_window.move(resolution.center() - app_window.rect().center())
                    sys.exit(app.exec_())
                

                And button to the layout )

                PyQt/PySide

                1 Reply Last reply
                2
                • S Offline
                  S Offline
                  Samuel Bachorik
                  wrote on 17 Apr 2020, 20:10 last edited by
                  #8

                  @Volodymyr14 Thank you for tip !!!

                  JonBJ 1 Reply Last reply 18 Apr 2020, 07:35
                  0
                  • V Offline
                    V Offline
                    Volodymyr14
                    wrote on 17 Apr 2020, 20:23 last edited by
                    #9

                    @Samuel-Bachorik no problem. The second variant is better because the screens are different and the size will be from minimum signed to a resolution of the screen. Really, in applications, it is not a good idea to use fixed sizes, set geometry, fixed resize and move. No fixed integers with sizes, just relative values. For example, to the fixed size put the size of sceen or widget divided on 2.

                    PyQt/PySide

                    1 Reply Last reply
                    1
                    • S Samuel Bachorik
                      17 Apr 2020, 20:10

                      @Volodymyr14 Thank you for tip !!!

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on 18 Apr 2020, 07:35 last edited by JonB
                      #10

                      @Samuel-Bachorik
                      All this self.b1.move(120, 155)-type stuff is possible but is usually not the right way to go about things. You would normally create QLayouts on your widgets --- if you are really using a QMainWindow for your app that would be on the QMainWindow::centralWidget() --- and then add your child widgets onto those layouts. Not doing so may lead to unexpected sizing/positioning issues. If you have not read through https://doc.qt.io/qt-5/layout.html, may I suggest you do so and reconsider in that light.

                      1 Reply Last reply
                      1
                      • S Offline
                        S Offline
                        Samuel Bachorik
                        wrote on 20 Apr 2020, 15:41 last edited by Samuel Bachorik
                        #11

                        Thank you for you help guys ! But iam not sure exatly about these sizes of my window. When i was working GUI in Tkinter whole program was able to scale without doing something extra. But at least how can i stop to scaling my window ? Just permament ressolution and no resizing allowed. You know also when i do not define set geometry from where this program know how big my window should be ?

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          Samuel Bachorik
                          wrote on 20 Apr 2020, 18:00 last edited by
                          #12

                          I need to learn and figure it out how to make this in right way. What should i do when i want scale with all widgeds in window when i try to resize it while using.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 20 Apr 2020, 18:26 last edited by
                            #13

                            Hi,

                            Use layouts.

                            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
                            2
                            • S Offline
                              S Offline
                              Samuel Bachorik
                              wrote on 21 Apr 2020, 08:01 last edited by
                              #14

                              Thank you guys for your help !

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                Volodymyr14
                                wrote on 21 Apr 2020, 09:18 last edited by
                                #15

                                @Samuel-Bachorik You don`t need to care about scaling. If you will use a resolution of the desktop you will have the window that will be similar for any device with any screen resolution. To build the elements inside this window you can build these elements (buttons, fields, etc) with layouts without setting sizes explicitly. It is better to use the QGridLayout, or you can use QVBoxLayout or QHBoxLayout if the app is simple in functional elements. Or another way to make sizes relative to the window. For example:

                                self.button.setFixedWidth(self.width() / 3)
                                

                                That will be button width as one-third of the window size, and it will work for any device with any resolution. And do not any these "resize(100, 100)".

                                PyQt/PySide

                                1 Reply Last reply
                                1

                                1/15

                                17 Apr 2020, 17:46

                                • Login

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