qt-material-widgets/components/checkbox.cpp

68 lines
1.5 KiB
C++
Raw Normal View History

2016-04-14 13:47:27 +00:00
#include <QWidget>
#include <QPainter>
2016-04-18 08:36:30 +00:00
#include <QStylePainter>
#include <QStyleOptionButton>
2016-03-19 08:32:49 +00:00
#include "checkbox.h"
2016-04-14 13:47:27 +00:00
Checkbox::Checkbox(QWidget *parent)
2016-04-18 08:36:30 +00:00
: QAbstractButton(parent)
2016-04-14 13:47:27 +00:00
{
2016-04-18 08:36:30 +00:00
setFixedSize(200, 200);
2016-04-14 13:47:27 +00:00
}
Checkbox::~Checkbox()
{
}
void Checkbox::mousePressEvent(QMouseEvent *event)
{
2016-04-18 08:36:30 +00:00
QAbstractButton::mousePressEvent(event);
2016-04-14 13:47:27 +00:00
}
void Checkbox::mouseReleaseEvent(QMouseEvent *event)
{
2016-04-18 08:36:30 +00:00
QAbstractButton::mouseReleaseEvent(event);
2016-04-14 13:47:27 +00:00
}
void Checkbox::paintEvent(QPaintEvent *event)
{
2016-04-18 08:36:30 +00:00
Q_UNUSED(event)
2016-04-14 13:47:27 +00:00
2016-04-18 08:36:30 +00:00
QStylePainter p(this);
QStyleOptionButton opt;
initStyleOption(&opt);
p.drawControl(QStyle::CE_CheckBox, opt);
2016-04-14 13:47:27 +00:00
2016-04-18 08:36:30 +00:00
p.drawRect(rect().adjusted(0, 0, -1, -1)); // tmp
}
void Checkbox::initStyleOption(QStyleOptionButton *option) const
{
if (!option)
return;
//Q_D(const QCheckBox);
option->initFrom(this);
/*
if (d->down)
option->state |= QStyle::State_Sunken;
if (d->tristate && d->noChange)
option->state |= QStyle::State_NoChange;
else
option->state |= d->checked ? QStyle::State_On : QStyle::State_Off;
*/
if (testAttribute(Qt::WA_Hover) && underMouse()) {
/*
if (d->hovering)
option->state |= QStyle::State_MouseOver;
else
option->state &= ~QStyle::State_MouseOver;
*/
}
option->text = "Label label";
/*
option->text = d->text;
option->icon = d->icon;
option->iconSize = iconSize();
*/
2016-04-14 13:47:27 +00:00
}