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. QFormLayout() set window size - which is the best solution?

QFormLayout() set window size - which is the best solution?

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 479 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
    PythonQTMarlem
    wrote on last edited by
    #1

    Hello,

    here my code:

    import sys
    from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, \
        QPushButton, QFormLayout, QLineEdit
    
    class Window(QWidget):
        define __init__(self):
            super().__init__()
            self.UI()
    
        define UI(self):
            self.setWindowTitle("QFormLayout()")
            self.lname = QLabel("&Name:")
            self.nameLineEdit = QLineEdit()
            self.lmail = QLabel("&Email:")
            self.emailLineEdit = QLineEdit()
            self.lname.setBuddy(self.nameLineEdit)
            self.lmail.setBuddy(self.emailLineEdit)
            self.btn_programm_beenden = QPushButton("En&de", self)
            self.btn_terminate_program.setDefault(True)
            self.btn_programm_beenden.clicked.connect( self.programm_beeden)
    
            formLayout = QFormLayout()
            #Several control elements can be placed in a row
            #to be included
            formLayout.addRow(self.lname,self.nameLineEdit)
            formLayout.addRow(self.lmail,self.emailLineEdit)
            formLayout.addRow(self.btn_terminate_program)
            self.setLayout(formLayout)
    
        def program_finished(self):
            QApplication.instance().quit()
    
    
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec())
    

    I know that you can set the window size with setGeometry. Disadvantage: The use of coordinates could cause problems in terms of platform independence.

    Then today I found out that you can set the window size with setFixedHeight and setFixedWidth. The charm of this solution is that the window is centered. Disadvantage: The user cannot change the fixed size with the computer mouse.

    I'm looking for a solution
    which is platform independent
    The window is centered
    The user can adjust the window size.

    What can you recommend me?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean you would like for your application window to be shown centered on whatever screen the user starts your application on ?

      If so you should take a look at the QScreen class.

      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

      • Login

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