add property to change track width

This commit is contained in:
laserpants 2016-05-11 20:26:19 +03:00
parent be270caa5a
commit e17b6367b1
5 changed files with 57 additions and 5 deletions

View File

@ -65,6 +65,21 @@ QColor Slider::trackColor() const
return d->trackColor; return d->trackColor;
} }
void Slider::setTrackWidth(int width)
{
Q_D(Slider);
d->trackWidth = width;
update();
}
int Slider::trackWidth() const
{
Q_D(const Slider);
return d->trackWidth;
}
void Slider::sliderChange(SliderChange change) void Slider::sliderChange(SliderChange change)
{ {
Q_D(Slider); Q_D(Slider);

View File

@ -11,6 +11,7 @@ class Slider : public QAbstractSlider
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor) Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor)
Q_PROPERTY(int trackWidth WRITE setTrackWidth READ trackWidth)
public: public:
explicit Slider(QWidget *parent = 0); explicit Slider(QWidget *parent = 0);
@ -26,6 +27,9 @@ public:
void setTrackColor(const QColor &color); void setTrackColor(const QColor &color);
QColor trackColor() const; QColor trackColor() const;
void setTrackWidth(int width);
int trackWidth() const;
signals: signals:
void changedToMinimum(); void changedToMinimum();
void changedFromMinimum(); void changedFromMinimum();

View File

@ -38,6 +38,7 @@ public:
bool pageStepMode; bool pageStepMode;
int stepTo; int stepTo;
int oldValue; int oldValue;
int trackWidth;
QColor trackColor; QColor trackColor;
}; };
@ -50,6 +51,7 @@ SliderPrivate::SliderPrivate(Slider *parent)
pageStepMode(false), pageStepMode(false),
stepTo(0), stepTo(0),
oldValue(parent->value()), oldValue(parent->value()),
trackWidth(2),
trackColor(QColor(200, 200, 200)) trackColor(QColor(200, 200, 200))
{ {
parent->setMouseTracking(true); parent->setMouseTracking(true);
@ -218,10 +220,12 @@ QRectF SliderPrivate::trackGeometry() const
{ {
Q_Q(const Slider); Q_Q(const Slider);
qreal hw = static_cast<qreal>(trackWidth)/2;
return Qt::Horizontal == q->orientation() return Qt::Horizontal == q->orientation()
? QRectF(SLIDER_MARGIN, q->rect().height()/2 - 1, ? QRectF(SLIDER_MARGIN, q->rect().height()/2 - hw,
q->rect().width() - SLIDER_MARGIN*2, 2) q->rect().width() - SLIDER_MARGIN*2, hw*2)
: QRectF(q->rect().width()/2 - 1, SLIDER_MARGIN, 2, : QRectF(q->rect().width()/2 - hw, SLIDER_MARGIN, hw*2,
q->rect().height() - SLIDER_MARGIN*2); q->rect().height() - SLIDER_MARGIN*2);
} }

View File

@ -1,4 +1,5 @@
#include <QLayout> #include <QLayout>
#include <QPushButton>
#include "flatbuttonexamples.h" #include "flatbuttonexamples.h"
#include "components/flatbutton.h" #include "components/flatbutton.h"
#include "exampleview.h" #include "exampleview.h"
@ -43,6 +44,24 @@ FlatButtonExamples::FlatButtonExamples(QWidget *parent)
); );
frame->setWidget(view); frame->setWidget(view);
layout->addWidget(frame);
}
{
QPushButton *flatButton = new QPushButton;
flatButton->setText("Press me!");
flatButton->setIcon(QIcon("../qt-material-widgets/face.svg"));
flatButton->setMinimumSize(200, 50);
flatButton->setCheckable(true);
ExampleView *view = new ExampleView;
view->setWidget(flatButton);
Frame *frame = new Frame;
frame->setCodeSnippet(
""
);
frame->setWidget(view);
layout->addWidget(frame); layout->addWidget(frame);
} }
} }

View File

@ -3,6 +3,7 @@
#include <QPushButton> #include <QPushButton>
#include <QLineEdit> #include <QLineEdit>
#include <QSlider> #include <QSlider>
#include <QLabel>
#include <QCheckBox> #include <QCheckBox>
#include "sliderexamples.h" #include "sliderexamples.h"
#include "components/slider.h" #include "components/slider.h"
@ -198,24 +199,33 @@ SliderExamples::SliderExamples(QWidget *parent)
widget->setLayout(layout); widget->setLayout(layout);
widget->setMinimumWidth(350); widget->setMinimumWidth(350);
Slider *slider = new Slider; Slider *slider;
QHBoxLayout *hLayout;
QHBoxLayout *hLayout = new QHBoxLayout; slider = new Slider;
hLayout = new QHBoxLayout;
hLayout->addWidget(new QLabel("R"));
hLayout->addWidget(slider); hLayout->addWidget(slider);
hLayout->addWidget(new QLineEdit);
layout->addLayout(hLayout); layout->addLayout(hLayout);
slider = new Slider; slider = new Slider;
hLayout = new QHBoxLayout; hLayout = new QHBoxLayout;
hLayout->addWidget(new QLabel("G"));
hLayout->addWidget(slider); hLayout->addWidget(slider);
hLayout->addWidget(new QLineEdit);
layout->addLayout(hLayout); layout->addLayout(hLayout);
slider = new Slider; slider = new Slider;
hLayout = new QHBoxLayout; hLayout = new QHBoxLayout;
hLayout->addWidget(new QLabel("B"));
hLayout->addWidget(slider); hLayout->addWidget(slider);
hLayout->addWidget(new QLineEdit);
layout->addLayout(hLayout); layout->addLayout(hLayout);