draw basic Slider track geometry
This commit is contained in:
parent
25b5015e33
commit
97cd0651d6
|
@ -13,12 +13,30 @@ Slider::~Slider()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Slider::setOrientation(Qt::Orientation orientation)
|
||||||
|
{
|
||||||
|
Q_D(Slider);
|
||||||
|
d->orientation = orientation;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::Orientation Slider::orientation() const
|
||||||
|
{
|
||||||
|
Q_D(const Slider);
|
||||||
|
return d->orientation;
|
||||||
|
}
|
||||||
|
|
||||||
void Slider::paintEvent(QPaintEvent *event)
|
void Slider::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
Q_D(Slider);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
|
d->paintTrack(&painter);
|
||||||
|
d->paintThumb(&painter);
|
||||||
|
|
||||||
#ifdef DEBUG_LAYOUT
|
#ifdef DEBUG_LAYOUT
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setColor(Qt::red);
|
pen.setColor(Qt::red);
|
||||||
|
|
|
@ -14,6 +14,9 @@ public:
|
||||||
explicit Slider(QWidget *parent = 0);
|
explicit Slider(QWidget *parent = 0);
|
||||||
~Slider();
|
~Slider();
|
||||||
|
|
||||||
|
void setOrientation(Qt::Orientation orientation);
|
||||||
|
Qt::Orientation orientation() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define SLIDER_P_H
|
#define SLIDER_P_H
|
||||||
|
|
||||||
#include "slider.h"
|
#include "slider.h"
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
class SliderPrivate
|
class SliderPrivate
|
||||||
{
|
{
|
||||||
|
@ -10,11 +11,47 @@ class SliderPrivate
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SliderPrivate(Slider *parent)
|
SliderPrivate(Slider *parent)
|
||||||
: q_ptr(parent)
|
: q_ptr(parent),
|
||||||
|
orientation(Qt::Horizontal)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect trackGeometry() const
|
||||||
|
{
|
||||||
|
Q_Q(const Slider);
|
||||||
|
|
||||||
|
return Qt::Horizontal == orientation
|
||||||
|
? QRect(0, q->rect().height()/2 - 1, q->rect().width(), 2)
|
||||||
|
: QRect(q->rect().width()/2 - 1, 0, 2, q->rect().height());
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintTrack(QPainter *painter)
|
||||||
|
{
|
||||||
|
Q_Q(Slider);
|
||||||
|
|
||||||
|
QBrush brush;
|
||||||
|
brush.setStyle(Qt::SolidPattern);
|
||||||
|
brush.setColor(QColor(0, 0, 0, 255));
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
painter->fillRect(trackGeometry(), brush);
|
||||||
|
painter->restore();
|
||||||
|
|
||||||
|
#ifdef DEBUG_LAYOUT
|
||||||
|
painter->drawRect(q->rect().adjusted(1, 1, -2, -2));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintThumb(QPainter *painter)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
Slider *const q_ptr;
|
Slider *const q_ptr;
|
||||||
|
|
||||||
|
Qt::Orientation orientation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SLIDER_P_H
|
#endif // SLIDER_P_H
|
||||||
|
|
Loading…
Reference in New Issue