当前位置:   article > 正文

QTabWidget类的使用_class qtablewidget' has no member named 'addtab

class qtablewidget' has no member named 'addtab
QTabWidget类的使用
//test.h
#include <QWidget>
#include <QDialog>
#include <QTabWidget>
class TabDialog:public QDialog
{
Q_OBJECT
public:
    TabDialog(QWidget *parent=0);
private:
    QTabWidget *tabWidget;
};
class ATab:public QWidget
{
Q_OBJECT
public:
    ATab(QWidget *parent=0);
};
class BTab:public QWidget
{
Q_OBJECT
public:
    BTab(QWidget *parent=0);
};
 
//test.cpp
#include "test.h"
#include <QLabel>
#include <QString>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
TabDialog::TabDialog(QWidget *parent):QDialog(parent)
{
tabWidget=new QTabWidget;
tabWidget->addTab(new ATab,QString("ATab"));
tabWidget->addTab(new BTab,QString("BTab"));
QPushButton *ok=new QPushButton(tr("OK"));
QPushButton *cancel=new QPushButton(tr("Cancel"));
connect(ok,SIGNAL(clicked()),this,SLOT(accept()));
connect(cancel,SIGNAL(clicked()),this,SLOT(reject()));
QHBoxLayout *btnLayout=new QHBoxLayout;
btnLayout->addStretch(1);
btnLayout->addWidget(ok);
btnLayout->addWidget(cancel);
QVBoxLayout *mainLayout=new QVBoxLayout;
mainLayout->addWidget(tabWidget);
mainLayout->addLayout(btnLayout);
setLayout(mainLayout);
resize(500,300);
setWindowTitle(tr("Tab Dialog"));
}
ATab::ATab(QWidget *parent):QWidget(parent)
{
QLabel *aLabel=new QLabel(tr("I am ATab"),this);
}
BTab::BTab(QWidget *parent):QWidget(parent)
{
QLabel *bLabel=new QLabel(tr("I am BTab"),this);
}

//main.cpp
#include <QApplication>
#include "test.h"
int main(int argc,char **argv)
{
QApplication app(argc,argv);
TabDialog t;
t.show();
return app.exec();
}
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/968076
推荐阅读
相关标签
  

闽ICP备14008679号