astiolo
28th May 2011, 07:53
I am experimenting with a program to log the work needed on a car and. I have created a stacked layout, with group boxes for each layout. I want to connect a button in a group box to make it change to another layout. I don't understand linking to children and parents properly so I can't get it to work.
I want to connect the addCar button signal 'clicked()' in carSelectionPage to the stacked layout slot 'setCurrentIndex(1)'. Where do I put the connect code and how do I refer to both items?
Alternatively if there is a better way of having separate windows which I can navigate between, that would be good.
#include <QtGui>
#include "cardiary.h"
#include <QStackedLayout>
CarDiary::CarDiary(QWidget *parent)
: QWidget(parent)
{
QStackedLayout *stackedLayout = new QStackedLayout;
stackedLayout->addWidget(carSelectionPage());
stackedLayout->addWidget(addCarPage());
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(stackedLayout);
setLayout(mainLayout);
stackedLayout->setCurrentIndex(0);
}
QGroupBox *CarDiary::carSelectionPage()
{
QGroupBox *groupBox = new QGroupBox();
QVBoxLayout *carList = new QVBoxLayout;
QPushButton *addCar = new QPushButton(tr("&Add Car"));
QPushButton *car1 = new QPushButton(tr("&MX 5"));
carList->addWidget(car1);
carList->addWidget(addCar);
groupBox->setLayout(carList);
return groupBox;
}
QGroupBox *CarDiary::addCarPage()
{
QGroupBox *groupBox = new QGroupBox();
QVBoxLayout *layout = new QVBoxLayout;
QLabel *carNameLabel = new QLabel(tr("Car Name:"));
QLineEdit *carNameInput = new QLineEdit();
layout->addWidget(carNameLabel);
layout->addWidget(carNameInput);
groupBox->setLayout(layout);
return groupBox;
}
I want to connect the addCar button signal 'clicked()' in carSelectionPage to the stacked layout slot 'setCurrentIndex(1)'. Where do I put the connect code and how do I refer to both items?
Alternatively if there is a better way of having separate windows which I can navigate between, that would be good.
#include <QtGui>
#include "cardiary.h"
#include <QStackedLayout>
CarDiary::CarDiary(QWidget *parent)
: QWidget(parent)
{
QStackedLayout *stackedLayout = new QStackedLayout;
stackedLayout->addWidget(carSelectionPage());
stackedLayout->addWidget(addCarPage());
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(stackedLayout);
setLayout(mainLayout);
stackedLayout->setCurrentIndex(0);
}
QGroupBox *CarDiary::carSelectionPage()
{
QGroupBox *groupBox = new QGroupBox();
QVBoxLayout *carList = new QVBoxLayout;
QPushButton *addCar = new QPushButton(tr("&Add Car"));
QPushButton *car1 = new QPushButton(tr("&MX 5"));
carList->addWidget(car1);
carList->addWidget(addCar);
groupBox->setLayout(carList);
return groupBox;
}
QGroupBox *CarDiary::addCarPage()
{
QGroupBox *groupBox = new QGroupBox();
QVBoxLayout *layout = new QVBoxLayout;
QLabel *carNameLabel = new QLabel(tr("Car Name:"));
QLineEdit *carNameInput = new QLineEdit();
layout->addWidget(carNameLabel);
layout->addWidget(carNameInput);
groupBox->setLayout(layout);
return groupBox;
}