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. pyside6 The move method cannot move the specified parameter under the ubuntu22.04 system,How should this problem be solved so that it can be centered horizontally and vertically
Forum Updated to NodeBB v4.3 + New Features

pyside6 The move method cannot move the specified parameter under the ubuntu22.04 system,How should this problem be solved so that it can be centered horizontally and vertically

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 4 Posters 418 Views
  • 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
    star2
    wrote on last edited by
    #1

    The following example code is moved in the dialog move in pyside6 using the ubuntu22.04 system, but the results do not achieve the desired centering effect

    from PySide6.QtWidgets import QApplication, QDialog
    from PySide6.QtCore import Qt, QRect
    
    class MyDialog(QDialog):
        def __init__(self, parent=None):
            super().__init__(parent)
            screen = QApplication.primaryScreen()
            screen_size = screen.size()
            center_x = screen_size.width() // 2
            center_y = screen_size.height() // 2
            self.show()
            self.move(center_x,center_y)
    
    if __name__ == "__main__":
        app = QApplication([])
        dialog = MyDialog()
        dialog.show()
        app.exec()
    

    The actual effect of running in ubuntu22.04 is shown below:
    6b27a8f3-2e33-4050-9e57-191fcd0e97d0-image.png

    How should this problem be solved so that it can be centered horizontally and vertically

    jsulmJ 1 Reply Last reply
    0
    • JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      If you are under Wayland you may not be able to control window positions.

      1 Reply Last reply
      0
      • S star2

        The following example code is moved in the dialog move in pyside6 using the ubuntu22.04 system, but the results do not achieve the desired centering effect

        from PySide6.QtWidgets import QApplication, QDialog
        from PySide6.QtCore import Qt, QRect
        
        class MyDialog(QDialog):
            def __init__(self, parent=None):
                super().__init__(parent)
                screen = QApplication.primaryScreen()
                screen_size = screen.size()
                center_x = screen_size.width() // 2
                center_y = screen_size.height() // 2
                self.show()
                self.move(center_x,center_y)
        
        if __name__ == "__main__":
            app = QApplication([])
            dialog = MyDialog()
            dialog.show()
            app.exec()
        

        The actual effect of running in ubuntu22.04 is shown below:
        6b27a8f3-2e33-4050-9e57-191fcd0e97d0-image.png

        How should this problem be solved so that it can be centered horizontally and vertically

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @star2 said in pyside6 The move method cannot move the specified parameter under the ubuntu22.04 system,How should this problem be solved so that it can be centered horizontally and vertically:

        self.move(center_x,center_y)

        I'm not sure this will work in the constructor of the widget. Try to call move from a slot connected to a one shot QTimer.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • F Offline
          F Offline
          friedemannkleint
          wrote on last edited by
          #4

          Are you maybe using Wayland - it does not support moving to coordinates.

          1 Reply Last reply
          0
          • JonBJ JonB referenced this topic on

          • Login

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