class SliderWidget
: public QWidget{
Q_OBJECT
public:
explicit SliderWidget
(QWidget * parent
= 0) , mRed
(new QSlider(Qt
::Horizontal)) , mBlue
(new QSlider(Qt
::Horizontal)) , mWhite
(new QSlider(Qt
::Horizontal)) , mGreen
(new QSlider(Qt
::Horizontal)) , mWhiteValue
(new QLabel("0")) , mGreenValue
(new QLabel("0")) , mColorValue
(new QLabel("0x00000000")) {
gridLayout
->addWidget
(new QLabel("Red"),
0,
0,
1,
1);
gridLayout
->addWidget
(new QLabel("Blue"),
1,
0,
1,
1);
gridLayout
->addWidget
(new QLabel("White"),
2,
0,
1,
1);
gridLayout
->addWidget
(new QLabel("Green"),
3,
0,
1,
1);
gridLayout
->addWidget
(new QLabel("Color"),
4,
0,
1,
1);
gridLayout->addWidget(mRedValue, 0, 1, 1, 1);
gridLayout->addWidget(mBlueValue, 1, 1, 1, 1);
gridLayout->addWidget(mWhiteValue, 2, 1, 1, 1);
gridLayout->addWidget(mGreenValue, 3, 1, 1, 1);
gridLayout->addWidget(mColorValue, 4, 1, 1, 1);
gridLayout->addWidget(mRed, 0, 2, 1, 1);
gridLayout->addWidget(mBlue, 1, 2, 1, 1);
gridLayout->addWidget(mWhite, 2, 2, 1, 1);
gridLayout->addWidget(mGreen, 3, 2, 1, 1);
mRed->setRange(0, 255);
mBlue->setRange(0, 255);
mWhite->setRange(0, 255);
mGreen->setRange(0, 255);
connect(mRed, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mBlue, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mWhite, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mGreen, SIGNAL(valueChanged(int)), SLOT(updateValues()));
}
private slots:
void updateValues(void)
{
mRedValue
->setText
(QString::number(mRed
->value
()));
mBlueValue
->setText
(QString::number(mBlue
->value
()));
mWhiteValue
->setText
(QString::number(mWhite
->value
()));
mGreenValue
->setText
(QString::number(mGreen
->value
()));
val
+= QString::number(mRed
->value
(),
16);
val
+= "," + QString::number(mBlue
->value
(),
16);
val
+= "," + QString::number(mWhite
->value
(),
16);
val
+= "," + QString::number(mGreen
->value
(),
16);
mColorValue->setText(val.toUpper());
}
private:
};
class SliderWidget : public QWidget
{
Q_OBJECT
public:
explicit SliderWidget(QWidget * parent = 0)
: QWidget(parent)
, mRed(new QSlider(Qt::Horizontal))
, mBlue(new QSlider(Qt::Horizontal))
, mWhite(new QSlider(Qt::Horizontal))
, mGreen(new QSlider(Qt::Horizontal))
, mRedValue(new QLabel("0"))
, mBlueValue(new QLabel("0"))
, mWhiteValue(new QLabel("0"))
, mGreenValue(new QLabel("0"))
, mColorValue(new QLabel("0x00000000"))
{
QGridLayout * gridLayout = new QGridLayout(this);
gridLayout->addWidget(new QLabel("Red"), 0, 0, 1, 1);
gridLayout->addWidget(new QLabel("Blue"), 1, 0, 1, 1);
gridLayout->addWidget(new QLabel("White"), 2, 0, 1, 1);
gridLayout->addWidget(new QLabel("Green"), 3, 0, 1, 1);
gridLayout->addWidget(new QLabel("Color"), 4, 0, 1, 1);
gridLayout->addWidget(mRedValue, 0, 1, 1, 1);
gridLayout->addWidget(mBlueValue, 1, 1, 1, 1);
gridLayout->addWidget(mWhiteValue, 2, 1, 1, 1);
gridLayout->addWidget(mGreenValue, 3, 1, 1, 1);
gridLayout->addWidget(mColorValue, 4, 1, 1, 1);
gridLayout->addWidget(mRed, 0, 2, 1, 1);
gridLayout->addWidget(mBlue, 1, 2, 1, 1);
gridLayout->addWidget(mWhite, 2, 2, 1, 1);
gridLayout->addWidget(mGreen, 3, 2, 1, 1);
mRed->setRange(0, 255);
mBlue->setRange(0, 255);
mWhite->setRange(0, 255);
mGreen->setRange(0, 255);
connect(mRed, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mBlue, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mWhite, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mGreen, SIGNAL(valueChanged(int)), SLOT(updateValues()));
}
private slots:
void updateValues(void)
{
mRedValue->setText(QString::number(mRed->value()));
mBlueValue->setText(QString::number(mBlue->value()));
mWhiteValue->setText(QString::number(mWhite->value()));
mGreenValue->setText(QString::number(mGreen->value()));
QString val;
val += QString::number(mRed->value(), 16);
val += "," + QString::number(mBlue->value(), 16);
val += "," + QString::number(mWhite->value(), 16);
val += "," + QString::number(mGreen->value(), 16);
mColorValue->setText(val.toUpper());
}
private:
QSlider * mRed;
QSlider * mBlue;
QSlider * mWhite;
QSlider * mGreen;
QLabel * mRedValue;
QLabel * mBlueValue;
QLabel * mWhiteValue;
QLabel * mGreenValue;
QLabel * mColorValue;
};
To copy to clipboard, switch view to plain text mode
Bookmarks