I have now created an independent example: (Sorry it does not use an .ui file)
main.cpp
#include <qt/qapplication.h>
#include "MainWindow.h"
int main(int argc, char** argv)
{
MainWindow mainWindow;
mainWindow.show();
return app.exec();
}
#include <qt/qapplication.h>
#include "MainWindow.h"
int main(int argc, char** argv)
{
QApplication app( argc, argv );
MainWindow mainWindow;
mainWindow.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
MainWindow.h
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_
#include <QtGui/QApplication>
#include <QtGui/QGridLayout>
#include <QtGui/QMainWindow>
#include <QtGui/QTextEdit>
#include <QtGui/QWidget>
{
Q_OBJECT
public:
{
MainWindow->resize(500, 500);
m_centralwidget
= new QWidget(MainWindow
);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
m_centralwidget->setSizePolicy(sizePolicy);
gridLayout
= new QWidget(m_centralwidget
);
gridLayout
->setGeometry
(QRect(50,
50,
300,
200));
gridLayout->setSizePolicy(sizePolicy);
gridLayout1->setContentsMargins(0, 0, 0, 0);
gridLayout1->addWidget(textEdit, 0, 0, 1, 1);
MainWindow->setCentralWidget(m_centralwidget);
} // setupUi
public:
MainWindow
(QWidget* parent
= 0, Qt
::WFlags flags
= 0);
virtual ~MainWindow(){};
//void resizeEvent(QResizeEvent * /* event */);
};
#endif
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_
#include <QtGui/QApplication>
#include <QtGui/QGridLayout>
#include <QtGui/QMainWindow>
#include <QtGui/QTextEdit>
#include <QtGui/QWidget>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
QWidget *m_centralwidget;
QWidget *gridLayout;
QGridLayout *gridLayout1;
QTextEdit *textEdit;
void setupUi(QMainWindow *MainWindow)
{
MainWindow->resize(500, 500);
m_centralwidget = new QWidget(MainWindow);
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
m_centralwidget->setSizePolicy(sizePolicy);
gridLayout = new QWidget(m_centralwidget);
gridLayout->setGeometry(QRect(50, 50, 300, 200));
gridLayout->setSizePolicy(sizePolicy);
textEdit = new QTextEdit(gridLayout);
gridLayout1 = new QGridLayout(gridLayout);
gridLayout1->setContentsMargins(0, 0, 0, 0);
gridLayout1->addWidget(textEdit, 0, 0, 1, 1);
MainWindow->setCentralWidget(m_centralwidget);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
public:
MainWindow(QWidget* parent = 0, Qt::WFlags flags = 0);
virtual ~MainWindow(){};
//void resizeEvent(QResizeEvent * /* event */);
};
#endif
To copy to clipboard, switch view to plain text mode
MainWindow.cpp
#include "MainWindow.h"
//
MainWindow
::MainWindow(QWidget* parent
/*= 0*/, Qt
::WFlags flags
/*= 0*/) : QMainWindow(parent, flags
){
setupUi(this);
}
//void MainWindow::resizeEvent(QResizeEvent * /* event */)
//{
// gridLayout->setGeometry(QRect(0, 0, this->width(), this->height()));
//}
#include "MainWindow.h"
//
MainWindow::MainWindow(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/) : QMainWindow(parent, flags)
{
setupUi(this);
}
//void MainWindow::resizeEvent(QResizeEvent * /* event */)
//{
// gridLayout->setGeometry(QRect(0, 0, this->width(), this->height()));
//}
To copy to clipboard, switch view to plain text mode
In this example nothing is resized if I resize the dialog.
Matthias
Bookmarks