Allow overriding color for FlatButton.
This commit is contained in:
parent
e2c940dcdc
commit
cc05f8174b
2 changed files with 12 additions and 1 deletions
|
|
@ -206,6 +206,11 @@ void FlatButton::setWidth(int w) {
|
||||||
resize(_width, height());
|
resize(_width, height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlatButton::setColorOverride(std::optional<QColor> color) {
|
||||||
|
_colorOverride = color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
int32 FlatButton::textWidth() const {
|
int32 FlatButton::textWidth() const {
|
||||||
return _st.font->width(_text);
|
return _st.font->width(_text);
|
||||||
}
|
}
|
||||||
|
|
@ -225,7 +230,11 @@ void FlatButton::paintEvent(QPaintEvent *e) {
|
||||||
|
|
||||||
p.setFont(isOver() ? _st.overFont : _st.font);
|
p.setFont(isOver() ? _st.overFont : _st.font);
|
||||||
p.setRenderHint(QPainter::TextAntialiasing);
|
p.setRenderHint(QPainter::TextAntialiasing);
|
||||||
p.setPen(isOver() ? _st.overColor : _st.color);
|
if (_colorOverride) {
|
||||||
|
p.setPen(*_colorOverride);
|
||||||
|
} else {
|
||||||
|
p.setPen(isOver() ? _st.overColor : _st.color);
|
||||||
|
}
|
||||||
|
|
||||||
const auto textRect = inner.marginsRemoved(
|
const auto textRect = inner.marginsRemoved(
|
||||||
_textMargins
|
_textMargins
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ public:
|
||||||
|
|
||||||
void setText(const QString &text);
|
void setText(const QString &text);
|
||||||
void setWidth(int w);
|
void setWidth(int w);
|
||||||
|
void setColorOverride(std::optional<QColor> color);
|
||||||
void setTextMargins(QMargins margins);
|
void setTextMargins(QMargins margins);
|
||||||
|
|
||||||
int32 textWidth() const;
|
int32 textWidth() const;
|
||||||
|
|
@ -107,6 +108,7 @@ private:
|
||||||
QString _text;
|
QString _text;
|
||||||
QMargins _textMargins;
|
QMargins _textMargins;
|
||||||
int _width = 0;
|
int _width = 0;
|
||||||
|
std::optional<QColor> _colorOverride;
|
||||||
|
|
||||||
const style::FlatButton &_st;
|
const style::FlatButton &_st;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue