Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6544639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:29:24+00:00 2026-05-25T11:29:24+00:00

I have a QMainWindow, which creates multiple QDialog child windows and sets itself as

  • 0

I have a QMainWindow, which creates multiple QDialog child windows and sets itself as their parent. When there is a single monitor, everything is OK and windows are centered correctly in the current monitor. But when I have multiple monitors, child windows tend to open on the primary monitor, and not on the monitor where the QMainWindow currently resides.

Note that my windows must be able to navigate outside of its parent (they each have the Qt.Window flag set).

So, how do I center a widget, relative to it’s parent position (i.e. centered on the QMainWindow) to avoid them opening up somewhere else?

Here is what I currently use to center my windows:

def centerOnScreen(widget):
    desktopWidget = QApplication.desktop()
    screenRect = desktopWidget.availableGeometry(widget)
    widget.move(screenRect.center() - widget.rect().center())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:29:24+00:00Added an answer on May 25, 2026 at 11:29 am

    Your code seems to be a good attempt to achieve the desired behavior. Two suggestions:

    1. Instead of taking the desktop parameters, try to directly find the left, top, width and height of your QMainWindow.
    2. Use this geometric information to move (and potentially size) your dialog to the center of your application, before calling the Exec method.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a QMainWindow which spawns a few wizards. The QMainWindow has a QFrame
I have a Qt Designer Class called MainWindow which is a QMainWindow. This class
I created a wpf application which have a single window which is getting started
I have a PySide app which has an icon for the MainWindow (a QMainWindow
I have a custom user control in XAML that creates a ItemsControl which ItemsPanel
I have a NIB which contains two windows, one is the app's main window
i have a QMainWindow. It has this parameters: this->setWindowFlags(Qt::Tool); this->setFocusPolicy(Qt::StrongFocus); this->setAttribute(Qt::WA_QuitOnClose,true); After showEvent calles
I would like to have a QMainWindow that can change it's look at runtime,
I have a class that inherits QMainWindow and I just want it to have
I have a KMainWindow: //file.h class MainWindow: public KMainWindow { public: MainWindow(QWidget *parent =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.