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
QtWS25 Last Chance

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 363 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 15 Jun 2024, 13:08 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

    J 1 Reply Last reply 17 Jun 2024, 05:36
    0
    • J Offline
      J Offline
      JonB
      wrote on 16 Jun 2024, 20:25 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
        15 Jun 2024, 13:08

        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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 17 Jun 2024, 05:36 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 17 Jun 2024, 06:25 last edited by
          #4

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

          1 Reply Last reply
          0
          • J JonB referenced this topic on 17 Jun 2024, 16:19

          1/4

          15 Jun 2024, 13:08

          • 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