Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QSpinBox>
#include <QSlider>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *janela = new QWidget;
janela->setWindowTitle("Modelo RGB!");
QPushButton *botaosair = new QPushButton("Sair");
QPushButton *botaoreset = new QPushButton("Reset");
QLabel *textoRed = new QLabel("Red");
QLabel *textoGreen = new QLabel("Green");
QLabel *textoBlue = new QLabel("Blue");
QSpinBox *spinBoxRed = new QSpinBox;
QSpinBox *spinBoxGreen = new QSpinBox;
QSpinBox *spinBoxBlue = new QSpinBox;
spinBoxRed->setRange(0,255);
spinBoxGreen->setRange(0,255);
spinBoxBlue->setRange(0,255);
QSlider *sliderRed = new QSlider(Qt::Horizontal);
QSlider *sliderGreen = new QSlider(Qt::Horizontal);
QSlider *sliderBlue = new QSlider(Qt::Horizontal);
sliderRed->setRange(0,255);
sliderGreen->setRange(0,255);
sliderBlue->setRange(0,255);
//Signals and slots
QObject::connect( spinBoxRed, SIGNAL(valueChanged(int)),
sliderRed, SLOT(setValue(int)));
QObject::connect( sliderRed, SIGNAL(valueChanged(int)),
spinBoxRed, SLOT(setValue(int)));
QObject::connect( spinBoxGreen, SIGNAL(valueChanged(int)),
sliderGreen, SLOT(setValue(int)));
QObject::connect( sliderGreen, SIGNAL(valueChanged(int)),
spinBoxGreen, SLOT(setValue(int)));
QObject::connect( spinBoxBlue, SIGNAL(valueChanged(int)),
sliderBlue, SLOT(setValue(int)));
QObject::connect( sliderBlue, SIGNAL(valueChanged(int)),
spinBoxBlue, SLOT(setValue(int)));
QObject::connect( botaosair, SIGNAL(clicked()),
&app, SLOT(quit()));
QObject::connect( botaoreset, SIGNAL(clicked()),
sliderRed, SLOT(setValue(33)));
sliderRed->setValue(100);
sliderGreen->setValue(100);
sliderBlue->setValue(100);
//layouts
QVBoxLayout *cores = new QVBoxLayout;
cores->addWidget(textoRed);
cores->addWidget(textoGreen);
cores->addWidget(textoBlue);
QVBoxLayout *spinbox = new QVBoxLayout;
spinbox->addWidget(spinBoxRed);
spinbox->addWidget(spinBoxGreen);
spinbox->addWidget(spinBoxBlue);
QVBoxLayout *slider = new QVBoxLayout;
slider->addWidget(sliderRed);
slider->addWidget(sliderGreen);
slider->addWidget(sliderBlue);
QHBoxLayout *layoutRGB = new QHBoxLayout;
layoutRGB->addItem(cores);
layoutRGB->addItem(spinbox);
layoutRGB->addItem(slider);
QHBoxLayout *layoutControlo = new QHBoxLayout;
layoutControlo->addWidget(botaoreset);
layoutControlo->addWidget(botaosair);
QVBoxLayout *layoutjanela = new QVBoxLayout;
layoutjanela->addItem(layoutRGB);
layoutjanela->addItem(layoutControlo);
janela->setLayout(layoutjanela);
janela->show();
return app.exec();
}
|