PDA

View Full Version : setFixedSize() not working



stbb24
3rd June 2012, 09:05
I tried using
QWidget::setFixedSize(463, 251); but when I run my program it's still resizable. I also tried different things like setting the minimumSize and maximumSize and changing the sizePolicy to fixed but the result is still the same.

I attached the file for reference.

ChrisW67
3rd June 2012, 12:06
It would help if you attached source files rather of a complete example rather than an intermediate like the ui_*h file.

There's nothing in that ui*h file that would stop the main window from resizing. Using setFixedsize() on the QMainWindow certainly works here:


#include <QApplication>
#include "ui_mainwindow.h" // your file as delivered

namespace Ui {
class MainWindow;
};

class MainWindow: public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p), ui(new Ui::MainWindow) {
ui->setupUi(this);
}
private:
Ui::MainWindow *ui;
};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
w.setFixedSize(463, 251);
a.exec();
}
#include "main.moc"


Since you have use absolute positioning and not used layouts the contents and the container are essentially independent and you forgo much control. The push buttons and edit boxes you placed with Designer are not moving with the widget that contains them as your QMainWindow is resizing it.

stbb24
4th June 2012, 00:31
Thanks totally work!!!