Здравствуйте. Есть класс ComparisionTable, наследуемый от QWidget с виджетами: два QLabel и один QTableWidget.
Была компоновка прописана в конструкторе:
QVBoxLayout *pVBox = new QVBoxLayout();
pVBox->addWidget(lblIS, 0, Qt::AlignTop);
pVBox->addWidget(lblOS, 0, Qt::AlignTop);
QHBoxLayout *pHBox = new QHBoxLayout(this);
pHBox->addWidget(pTable);
pHBox->addLayout(pVBox);
this->setLayout(pHBox);
Нужно создать класс PairwiseComp, который будет наследоваться от вышенаписанного класса, только добавить еще один QLabel и нужные для него методы. Создал:
PairwiseComp::PairwiseComp(ComparisionTableData data, QString name, QWidget *parent)
: ComparisionTable(data, parent)
{
lblName = new QLabel(this);
lblName->setText("<font color=blue>"+name+"</font>");
И надо будет компоновку поменять. Как можно поменять компоновку? Просто добавлять в конструктор не вариант.
test.h
#ifndef TEST_H
#define TEST_H
#include <QDialog>
#include <QLabel>
#include <QHBoxLayout>
namespace Ui {
class Test;
}
class Test : public QDialog
{
Q_OBJECT
public:
explicit Test(QWidget *parent = 0);
void method1();
void method2();
void method3();
virtual void DrawScreen();
~Test();
private:
Ui::Test *ui;
};
#endif // TEST_H
test.cpp
#include "test.h"
#include "ui_test.h"
Test::Test(QWidget *parent) :
QDialog(parent),
ui(new Ui::Test)
{
ui->setupUi(this);
}
void Test::DrawScreen()
{
QHBoxLayout *lay = new QHBoxLayout;
QLabel *l1 = new QLabel("1234");
QLabel *l2 = new QLabel("5678");
lay->addWidget(l1);
lay->addWidget(l2);
setLayout(lay);
show();
}
Test::~Test()
{
delete ui;
}
pairwisecomp.h
#ifndef PAIRWISECOMP_H
#define PAIRWISECOMP_H
#include <QWidget>
#include <QVBoxLayout>
#include "test.h"
class PairwiseComp : public Test
{
Q_OBJECT
public:
explicit PairwiseComp(QWidget *parent = 0);
void DrawScreen();
~PairwiseComp();
};
#endif // PAIRWISECOMP_H
pairwisecomp.cpp
#include "pairwisecomp.h"
PairwiseComp::PairwiseComp(QWidget *parent) : Test(parent)
{
}
void PairwiseComp::DrawScreen()
{
QVBoxLayout *lay = new QVBoxLayout;
QLabel *l1 = new QLabel("1234");
QLabel *l2 = new QLabel("5678");
QLabel *l3 = new QLabel("1234");
lay->addWidget(l1);
lay->addWidget(l2);
lay->addWidget(l3);
setLayout(lay);
show();
}
PairwiseComp::~PairwiseComp()
{
}
Вот этот пример вполне себе работоспособен. Изменяйте что и как вам нужно.
Сборка персонального компьютера от Artline: умный выбор для современных пользователей