implement raised button disabled look

This commit is contained in:
laserpants 2016-05-28 17:08:05 +03:00
parent f541a86301
commit 20db7569f3
3 changed files with 23 additions and 8 deletions

View File

@ -122,6 +122,20 @@ void RaisedButton::setRole(Material::Role role)
update();
}
bool RaisedButton::event(QEvent *event)
{
Q_D(RaisedButton);
if (QEvent::EnabledChange == event->type()) {
if (isEnabled()) {
d->machine.start();
} else {
d->machine.stop();
}
}
return FlatButton::event(event);
}
void RaisedButton::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
@ -135,13 +149,13 @@ void RaisedButton::paintEvent(QPaintEvent *event)
QBrush brush;
if (isEnabled()) {
brush.setStyle(Qt::SolidPattern);
brush.setColor(palette().color(QPalette::Active, QPalette::Background));
painter.setBrush(brush);
painter.setPen(Qt::NoPen);
painter.drawRoundedRect(rect(), 3, 3);
}
brush.setStyle(Qt::SolidPattern);
brush.setColor(isEnabled()
? palette().color(QPalette::Active, QPalette::Background)
: palette().color(QPalette::Disabled, QPalette::Background));
painter.setBrush(brush);
painter.setPen(Qt::NoPen);
painter.drawRoundedRect(rect(), 3, 3);
if (isEnabled()) {
const qreal hs = static_cast<qreal>(width())*d->delegate->focusHaloSize()/2;

View File

@ -16,6 +16,7 @@ public:
void setRole(Material::Role role) Q_DECL_OVERRIDE;
protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:

View File

@ -13,7 +13,7 @@ RaisedButtonExamples::RaisedButtonExamples(QWidget *parent)
raisedButton->setRole(Material::Primary);
raisedButton->setText("Press me!");
raisedButton->setDisabled(true);
//raisedButton->setDisabled(true);
//raisedButton->setFixedSize(400, 50);