MyDialog
::MyDialog(QWidget *parent, Qt
::WFlags flags
){
// test input
mTermName.append("term 1");
mTermName.append("term 2");
mValues.append(1.23);
mValues.append(3.4322);
Initialize(); // initializes mGridLayout with its content
mMainLayout->addLayout(mGridLayout, 0, 0);
Q_ASSERT(connect(btn, SIGNAL(clicked()), this, SLOT(slotPressed())));
mMainLayout->addWidget(btn, 1, 0);
setLayout(mMainLayout);
}
void MyDialog::slotPressed()
{
mValues[0] = 2.5;
Initialize();
}
void MyDialog::Initialize()
{
int nbrTerms = 2;
int row = 1;
for(int i=0; i<nbrTerms; i++)
{
double termValue = mValues[i];
QString parameterValueText
= QString("%1").
arg( termValue,
1,
'f',
3 );
mGridLayout->addWidget(nameLabel, row, 1);
mGridLayout->addWidget(termValueLabel,row, 2);
row++;
}
}
MyDialog::MyDialog(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
// test input
mTermName.append("term 1");
mTermName.append("term 2");
mValues.append(1.23);
mValues.append(3.4322);
QGridLayout *mMainLayout = new QGridLayout(this);
mGridLayout = new QGridLayout;
Initialize(); // initializes mGridLayout with its content
mMainLayout->addLayout(mGridLayout, 0, 0);
QPushButton *btn = new QPushButton("press me");
Q_ASSERT(connect(btn, SIGNAL(clicked()), this, SLOT(slotPressed())));
mMainLayout->addWidget(btn, 1, 0);
setLayout(mMainLayout);
}
void MyDialog::slotPressed()
{
mValues[0] = 2.5;
Initialize();
}
void MyDialog::Initialize()
{
int nbrTerms = 2;
int row = 1;
for(int i=0; i<nbrTerms; i++)
{
QString termName = QString("%1").arg(mTermName[i]);
double termValue = mValues[i];
QLabel *nameLabel = new QLabel(termName);
QString parameterValueText = QString("%1").arg( termValue, 1, 'f', 3 );
QLabel *termValueLabel = new QLabel(parameterValueText);
mGridLayout->addWidget(nameLabel, row, 1);
mGridLayout->addWidget(termValueLabel,row, 2);
row++;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks