|
|
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 |
#include <QApplication>
#include <QHBoxLayout>
#include <QSlider>
#include <QSpinBox>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
window->setWindowTitle("Enter Your Age");
QSpinBox *spinBox = new QSpinBox;
QSlider *slider = new QSlider(Qt::Horizontal);
QPushButton *botao = new QPushButton("Lixo");
QPushButton *sair = new QPushButton("Sair");
spinBox->setRange(0, 130);
slider->setRange(0, 130);
QObject::connect( sair, SIGNAL(clicked()),
&app, SLOT(quit()));
QObject::connect(spinBox, SIGNAL(valueChanged(int)),
slider, SLOT(setValue(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)),
spinBox, SLOT(setValue(int)));
slider->setValue(40);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(spinBox);
layout->addWidget(slider);
layout->addWidget(botao);
layout->addWidget(sair);
window->setLayout(layout);
window->show();
return app.exec();
}
|

|
|
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 |
#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(0)));
//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();
}
|
|
|
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 |
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QDialog>
class QPushButton;
class QLabel;
class QSpinBox;
class QSlider;
class QGridLayout;
class QVBoxLayout;
class QHBoxLayout;
class MainWindow : public QWidget
{
Q_OBJECT
public :
MainWindow ( QWidget* parent = 0 );
private slots :
void resetSliders ( );
private :
QPushButton *botaoReset;
QPushButton *botaoSair;
QLabel *textoRed;
QLabel *textoGreen;
QLabel *textoBlue;
QSpinBox *spinBoxRed;
QSpinBox *spinBoxGreen;
QSpinBox *spinBoxBlue;
QSlider *sliderRed;
QSlider *sliderGreen;
QSlider *sliderBlue;
};
#endif
|
|
|
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 |
#include <QtGui>
#include "mainwindow.h"
MainWindow::MainWindow ( QWidget *parent ) : QWidget ( parent )
{
botaoReset = new QPushButton ( "Reset" );
botaoSair = new QPushButton ( "Sair" );
textoRed = new QLabel ( "Red" );
textoGreen = new QLabel ( "Green" );
textoBlue = new QLabel ( "Blue" );
spinBoxRed = new QSpinBox;
spinBoxGreen = new QSpinBox;
spinBoxBlue = new QSpinBox;
spinBoxRed -> setRange ( 0, 255 );
spinBoxGreen -> setRange ( 0, 255 );
spinBoxBlue -> setRange ( 0, 255 );
sliderRed = new QSlider ( Qt::Horizontal );
sliderGreen = new QSlider ( Qt::Horizontal );
sliderBlue = new QSlider ( Qt::Horizontal );
sliderRed -> setRange ( 0, 255 );
sliderGreen -> setRange ( 0, 255 );
sliderBlue -> setRange ( 0, 255 );
// Signals and slots :
connect ( spinBoxRed, SIGNAL ( valueChanged ( int )), sliderRed,SLOT ( setValue ( int )));
connect ( sliderRed,SIGNAL ( valueChanged ( int )), spinBoxRed, SLOT ( setValue ( int )));
connect ( spinBoxGreen, SIGNAL ( valueChanged ( int )), sliderGreen, SLOT ( setValue ( int )));
connect ( sliderGreen, SIGNAL ( valueChanged ( int )), spinBoxGreen, SLOT ( setValue ( int )));
connect ( spinBoxBlue, SIGNAL ( valueChanged ( int )), sliderBlue, SLOT ( setValue ( int )));
connect ( sliderBlue, SIGNAL ( valueChanged ( int )), spinBoxBlue, SLOT ( setValue ( int )));
connect ( botaoSair, SIGNAL ( clicked ( )), this, SLOT ( close ( )));
connect ( botaoReset, SIGNAL ( clicked ( )), this, SLOT ( resetSliders ( )));
// Layouts :
QGridLayout *topLayout = new QGridLayout;
topLayout -> addWidget ( textoRed, 0, 0, 1, 1 );
topLayout -> addWidget ( spinBoxRed, 0, 1, 1, 1 );
topLayout -> addWidget ( sliderRed,0, 2, 1, 1 );
topLayout -> addWidget ( textoGreen, 1, 0, 1, 1 );
topLayout -> addWidget ( spinBoxGreen, 1, 1, 1, 1 );
topLayout -> addWidget ( sliderGreen, 1, 2, 1, 1 );
topLayout -> addWidget ( textoBlue,2, 0, 1, 1 );
topLayout -> addWidget ( spinBoxBlue, 2, 1, 1, 1 );
topLayout -> addWidget ( sliderBlue, 2, 2, 1, 1 );
QHBoxLayout *layoutControlo = new QHBoxLayout;
layoutControlo -> addWidget ( botaoReset );
layoutControlo -> addWidget ( botaoSair );
QVBoxLayout *layoutJanela = new QVBoxLayout;
layoutJanela -> addLayout ( topLayout );
layoutJanela -> addLayout ( layoutControlo );
setLayout ( layoutJanela );
}
void MainWindow::resetSliders ( )
{
sliderRed -> setValue ( 0 );
sliderGreen -> setValue ( 0 );
sliderBlue -> setValue ( 0 );
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <QApplication>
#include "mainwindow.h"
int main ( int argc, char *argv [] )
{
QApplication app ( argc, argv );
MainWindow *janela = new MainWindow;
janela -> setWindowTitle ( "Modelo RGB!" );
janela -> show ( );
return app.exec ( );
}
|