嗨,我正在尝试在 Qt 中制作一个简单的布局,首先布局根本无法正常工作,所有显示的只是一个取消按钮。所以我一直在搞乱,现在当我运行它时它运行没有错误但没有弹出窗口,不知道我能做些什么来导致这个?这是我的代码
#ifndef FILMINPUT_H
#define FILMINPUT_H
#include <QMainWindow>
#include "Film.h"
#include "FilmWriter.h"
#include <QLabel>
#include <QTextEdit>
#include <QPushButton>
namespace Ui {
class FilmInput;
}
class FilmInput : public QMainWindow
{
Q_OBJECT
public:
explicit FilmInput(QWidget *parent = 0);
~FilmInput();
private:
Ui::FilmInput *ui;
//widgets
QMainWindow* window;
QMenuBar* menubar;
QLabel* infoLabel;
QLabel* titleLabel;
QLabel* durationLabel;
QLabel* directorLabel;
QLabel* relDateLabel;
QTextEdit* titleEdit;
QTextEdit* durationEdit;
QTextEdit* directorEdit;
QTextEdit* relDateEdit;
QPushButton* saveBtn;
QPushButton* cancelBtn;
Film f;
//sets up gui and connects signals and slots
void setUpGui();
};
#endif // FILMINPUT_H
#include "filminput.h"
#include "ui_filminput.h"
#include <QtGui>
FilmInput::FilmInput(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FilmInput)
{
ui->setupUi(this);
setUpGui();
}
FilmInput::~FilmInput()
{
delete ui;
}
void FilmInput::setUpGui(){
//initialise widgets
infoLabel = new QLabel("Please enter film data which will be saved to a file",this);
titleLabel = new QLabel("Film Title",this);
durationLabel = new QLabel("Film Duration",this);
directorLabel = new QLabel("Film Director",this);
relDateLabel = new QLabel("Film Release Date",this);
titleEdit = new QTextEdit(this);
durationEdit = new QTextEdit(this);
directorEdit = new QTextEdit(this);
relDateEdit = new QTextEdit(this);
saveBtn = new QPushButton("Save Film",this);
cancelBtn = new QPushButton("Cancel",this);
//set layout
QVBoxLayout* layout = new QVBoxLayout();
layout->setMenuBar(menubar);
layout->addWidget(infoLabel);
layout->addWidget(titleLabel);
layout->addWidget(durationLabel);
layout->addWidget(directorLabel);
layout->addWidget(relDateLabel);
layout->addWidget(titleEdit);
layout->addWidget(durationEdit);
layout->addWidget(directorEdit);
layout->addWidget(relDateEdit);
layout->addWidget(saveBtn);
layout->addWidget(cancelBtn);
this->setLayout(layout);
this->setWindowTitle("Film Archive");
}
#include <QtGui/QApplication>
#include "filminput.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FilmInput w;
w.show();
return a.exec();
}