2

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>
Niklas
  • 23,674
  • 33
  • 131
  • 170
  • Why do you edit the code manually? Use Qt Designer – headsvk Aug 25 '13 at 12:33
  • I also tried it with the Qt designer. It doesn't work in both ways. – Niklas Aug 25 '13 at 21:09
  • I don't know about `QMainWindow` but for `QWidgets` it's sufficient to set width and height. But you can try setting `minimumSize' and `sizePolicy` to `Minimum` or `MinimumExpanding` if you don't want your window to be smaller than that. – headsvk Aug 26 '13 at 06:50

1 Answers1

2

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();
}
Andrea
  • 6,032
  • 2
  • 28
  • 55
  • Do you know how I can prevent the user from resizing the `MainWindow`? Something like `setResizeable(false)` – Niklas Aug 26 '13 at 17:35
  • 1
    Never tried that, but you could have a look at here: http://stackoverflow.com/questions/16673074/fully-disable-window-resize Hope it helps. – Andrea Aug 27 '13 at 07:07