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 8968851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:30:39+00:00 2026-06-15T17:30:39+00:00

I have a main window that I center this way in main.cpp : int

  • 0

I have a main window that I center this way in main.cpp :

int main(int argc, char *argv[])
{    
     QApplication app(argc, argv);
     QMainWindow *qmain = new QMainWindow;
     Ui_MainWindow ui;
     ui.setupUi(qmain);
     QRect r = qmain->geometry();
     r.moveCenter(QApplication::desktop()->availableGeometry().center());
     qmain->setGeometry(r); 
     qmain->show();
     return app.exec();
}

In this “qmain” main window, I can create another QMainWindow and I try to make stick (or glue I don’t know how to say) the two windows. Actually, I would like the right-top corner of the first one to be located at the left-top of the second one. For this, I use the following Ui_MainWindow’s member function :

void Ui_MainWindow::generate_IC()
{
qmenu = new QMainWindow;
DiskMenu = new Ui_DiskGalMenu;
DiskMenu->setupUi(qmenu);
setInitialDiskMenuPosition(qmenu, this);
qmenu->show();
}

and the setInitialDiskMenuPosition :

void Ui_MainWindow::setInitialDiskMenuPosition(QMainWindow *MainWindow, Ui_MainWindow *parent)
{
        QSize size = parent->widget->size();
        QDesktopWidget* desktop = QApplication::desktop();
        int width = desktop->width();
        int height = desktop->height();
        int mw = size.width();
        int mh = size.height();
        int right = (width/2) + (mw/2);
        int top = (height/2) - (mh/2);
       MainWindow->move(right, top);
}

But the problem is that I don’t get exactly what I want since the centralwidget size “parent-> widget->size()” only returns the size of the widget and not the whole “qmain” parent window. So I have a light shift because the borders of the “qmain” window are not taken in account like it is shown below :

enter image description here

If I could have access to the size of the whole parent window…

If anyone could help me

  • 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-06-15T17:30:40+00:00Added an answer on June 15, 2026 at 5:30 pm

    According to documentation you need to use parent->widget->frameGeometry().size() instead of parent->widget->size()

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

Sidebar

Related Questions

I have a main window, that opens another window. I want to close this
I have module application. When I run it, the main window of that app
i have a mvvm app that the main window is a tab control. i
I have an application with a main window that loads in text file(s) and
I have a Switch to window button on my main form that I'd like
I have a main window with a menu wich opens another window. This secondary
I have an openGL window that is 640x480 that I need to center in
I have a windows form on the main thread and another thread that does
I have main window which has inner grid components. When I press a button
I have a main window with a Gtk Button named openDialog. If I click

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.