0
对于我的课程,我应该编写一个叫做Qtunes的iTunes程序框架。我决定使用3个ListWidgets和一个TableWidget来做到这一点。所以我写了Qt Creator中下面的代码(我们应该通过手不使用设计的代码吧),Qt输出一个小盒子?
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QtGui>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
// ui(new Ui::MainWindow)
//{
// ui->setupUi(this);
//}
{
genreList = new QListWidget(this);
artistList = new QListWidget(this);
albumList = new QListWidget(this);
songTable = new QTableWidget(this);
genLabel = new QLabel(this);
genLabel->setText("Genre");
artistLabel = new QLabel(this);
artistLabel->setText("Artist");
albLabel = new QLabel(this);
albLabel->setText("Album");
QHBoxLayout *labelLayout = new QHBoxLayout;
labelLayout->addWidget(genLabel);
labelLayout->addWidget(artistLabel);
labelLayout->addWidget(albLabel);
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(genreList);
topLayout->addWidget(artistList);
topLayout->addWidget(albumList);
QHBoxLayout *bottomLayout = new QHBoxLayout;
bottomLayout->addWidget(songTable);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(labelLayout);
mainLayout->addLayout(topLayout);
mainLayout->addLayout(bottomLayout);
setLayout(mainLayout);
setWindowTitle("Version 2");
}
我没想到能有工作,但预计至少看到listWidgets和这样。相反,我得到这个:
http://postimage.org/image/krrs2ijmx/
我知道我做错了什么地方,我已经花了几个小时试图找到地方。 谢谢你的帮助。
尝试没有父创建标签,ListWidget和TableWidget,我的意思是这样genLabel =新QLabel(),genreList =新QListWidget();然后将这些小部件添加到布局 – 2013-02-22 06:52:35