简体   繁体   中英

Qt change MainWindow geometry

I want to change the size of the MainWindow. If I change the geometry of my Mainwindow to for instance 947 x 504, it is still smaller. Even if I change it a few more times and save the ui data file, it won't change. I am using Qt 5.1.0.

XML Code from mainwindow.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="enabled">
   <bool>true</bool>
  </property>
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>947</width>
    <height>504</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>SpeedReader [BETA]</string>
  </property>
  <widget class="QWidget" name="centralWidget"/>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>947</width>
     <height>21</height>
    </rect>
   </property>

You can use the resize() function. As an example, suppose that you want to apply a 1280x1024 resolution to the main window, as your application starts. You can do something like this:

int main( int argc, char **argv )
{
  QApplication app( argc, argv );  
  MainWindow w;
  w.resize(1280, 1024);
  w.show();  
  return app.exec();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM