I'm getting started with layouts and have some problems. I created a simple project with a QWidget as base class. I setup layouts in the ui file, and everything compiled, ran and resized fine. Then I added a base class that's supposed to keep track of multiple classes with their own ui-files. When I resize base, the widget contents doesn't follow. What am I doing wrong?
// main.cpp
#include <QtGui/QApplication>
#include "base.h"
int main(int argc, char *argv[])
{
base b;
b.show();
return a.exec();
}
//base.h
#ifndef BASE_H
#define BASE_H
#include <QWidget>
class Widget;
{
Q_OBJECT
public:
explicit base
(QWidget *parent
= 0);
signals:
public slots:
private:
Widget * w;
};
#endif // BASE_H
//base.cpp
#include "base.h"
#include "widget.h"
w(new Widget(this))
{
w->show();
}
// widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class Widget;
}
{
Q_OBJECT
public:
explicit Widget
(QWidget *parent
= 0);
~Widget();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
// widget.cpp
#include "widget.h"
#include "ui_widget.h"
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
// main.cpp
#include <QtGui/QApplication>
#include "base.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
base b;
b.show();
return a.exec();
}
//base.h
#ifndef BASE_H
#define BASE_H
#include <QWidget>
class Widget;
class base : public QWidget
{
Q_OBJECT
public:
explicit base(QWidget *parent = 0);
signals:
public slots:
private:
Widget * w;
};
#endif // BASE_H
//base.cpp
#include "base.h"
#include "widget.h"
base::base(QWidget *parent) :
QWidget(parent),
w(new Widget(this))
{
w->show();
}
// widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
// widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Added after 13 minutes:
I solved it by using a stacked layout in base, and adding widget to that.
Bookmarks