-2
时许设计摄像头应用程序,所以我有MenuBarClass(这将创建菜单图标),CameraViewClass(创建图像控件在那里得到实时显示图像),RecentImageClass(显示最近的图像),所以我想要在一个主窗口中显示所有类对象(例如:菜单图标,图像小部件,最新图像小部件)。我在菜单栏类中使用了所有类实例对象,但仍然无法在主窗口中显示所有内容。我没有使用ui表单。的Qt显示所有类对象(UI元素)到一个主窗口
class MenuBar : public QMainWindow
{
Q_OBJECT
public:
MenuBar(QWidget *parent = 0);
~MenuBar();
void CrateAction();
void CreateStatusbar();
public slots:
void open();
private:
CameraView *mview;
RecentImage *mImage;
QMenu *mFile;
QMenu *mPath;
QMenu *mSave;
QWidget *mcentralwidget;
QWidget *wid;
};
MenuBar::MenuBar(QWidget *parent)
: QMainWindow(parent),
mFile(NULL),
mPath(NULL),
mSave(NULL),
mcentralwidget(NULL)
{
mview=new CameraView(this);
mImage=new RecentImage(this);
//mcentralwidget=new QWidget(this);
//setCentralWidget(mcentralwidget);
resize(800,600);
CrateAction();
CreateStatusbar();
}
class CameraView : public QMainWindow
{
Q_OBJECT
public:
explicit CameraView(QWidget *parent = 0);
void SetCamera(const QCameraInfo& view);
void StartCamera();
void StopCamera();
void Record();
void Pause();
public slots:
private:
QWidget *mImageWidget;
QCamera *mCamera;
QCameraImageCapture *mImageCapture;
QMediaRecorder *mRecorder;
};
CameraView::CameraView(QWidget *parent) :
QMainWindow(parent),
mCamera(NULL),
mImageCapture(NULL),
mRecorder(NULL),
mImageWidget(NULL)
{
mImageWidget=new QWidget();
mImageWidget->setStyleSheet("border:1px solid black");
// mImageWidget->setGeometry(1,1,798,350);
}
class RecentImage : public QMainWindow
{
Q_OBJECT
public:
explicit RecentImage(QWidget *parent = 0);
void createScrollArea();
signals:
public slots:
private:
QWidget *mWidget1,*mWidget2;
QHBoxLayout *mHlayout;
QScrollArea *mScrollArea;
};
RecentImage::RecentImage(QWidget *parent) :
QMainWindow(parent),
mWidget1(NULL),
mWidget2(NULL),
mHlayout(NULL),
mScrollArea(NULL)
{
createScrollArea();
}
void RecentImage::createScrollArea()
{
QHBoxLayout *vLayout = new QHBoxLayout();
QScrollArea *scrollArea = new QScrollArea();
//scrollArea->setWidgetResizable(true);
QWidget *widget = new QWidget();
widget->setGeometry(0,200,600,150);
widget->setStyleSheet("border:1px solid black");
QHBoxLayout *vLayout2 = new QHBoxLayout(widget);
scrollArea->setWidget(widget);
vLayout->addWidget(scrollArea);
setCentralWidget(scrollArea);
for (int i = 0; i < 20; i++) {
QWidget *widget = new QWidget();
vLayout2->addWidget(widget);
}
show();
}