我想這樣爲什麼我的小部件不顯示?
在QT我創建的小部件,並把在主窗口部件創建佈局,問題是不可見的。沒有顯示任何部件。請幫我解決這個問題
完整的源代碼 sandbox.ifuturemec.com/test.zip
的源代碼 mainWindow.cpp
#include "mainwindow.h"
#include <QtGui>
#include "headerbar.h"
#include <QGridLayout>
#include <QPushButton>
#include <QBoxLayout>
#include "statusbar.h"
#include "leftpanel.h"
#include "rightpanel.h"
#include "centerpanel.h"
mainWindow::mainWindow(QWidget *parent) : QWidget(parent)
{
QGridLayout *layout=new QGridLayout(this);
headerBar *Header= new headerBar(this);
leftPanel *LeftPanel=new leftPanel(this);
centerPanel *CenterPanel=new centerPanel(this);
rightPanel *RightPanel=new rightPanel(this);
statusBar *Status=new statusBar(this);
QHBoxLayout *box=new QHBoxLayout();
box->addWidget(LeftPanel);
box->addWidget(CenterPanel);
box->addWidget(RightPanel);
layout->addWidget(Header,0,0);
layout->addLayout(box,1,0);
layout->addWidget(Status,2,0);
setLayout(layout);
}
mainWindow::~mainWindow() {}
mainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
class mainWindow : public QWidget
{
Q_OBJECT
public:
mainWindow(QWidget *parent = 0);
~mainWindow();
signals:
public slots:
};
#endif // MAINWINDOW_H
headerbar.cpp
#include "headerbar.h"
#include <QPushButton>
#include <QMessageBox>
headerBar::headerBar(QWidget *parent) : QWidget(parent)
{
this->setMaximumHeight(24);
this->setStyleSheet("background-color: rgb(85, 170, 255)");
}
headerBar::~headerBar(){}
headerbar.h
#ifndef HEADERBAR_H
#define HEADERBAR_H
#include <QWidget>
class headerBar : public QWidget
{
Q_OBJECT
public:
headerBar(QWidget *parent = 0);
~headerBar();
signals:
public slots:
};
#endif // HEADERBAR_H
請幫我解決這個問題。
謝謝。它正在工作。但我需要解決這個佈局,出小部件也應該全屏顯示。請提出一些建議。 – saravanan 2010-09-14 06:21:01