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