QSize WrappingPushButton
::sizeHint() const {
initStyleOption(&option);
QMargins m = getPaddingToLabel();
QRect r
= option.
fontMetrics.
boundingRect(0,
0, width
() - m.
right() - m.
left(),
2147483647, mTextFlags, text
());
size.setHeight(r.height() + m.top() + m.bottom());
return size;
}
{
initStyleOption(&option);
//This will prevent the style from drawing the text
option.text = "";
//Draw button
p.
drawControl(QStyle::CE_PushButton, option
);
//Draw Text
QMargins m = getPaddingToLabel();
QRect innerRectangle
= QRect(m.
right(), m.
top(), width
() - m.
right() - m.
left(), height
() - m.
top() - m.
bottom());
p.drawText(innerRectangle, mTextFlags, text());
}
QMargins WrappingPushButton::getPaddingToLabel() const
{
//TODO: How to get the real margins!
return QMargins(10,10,10,10);
}
QSize WrappingPushButton::sizeHint() const
{
QSize size = QPushButton::sizeHint();
QStyleOptionButton option;
initStyleOption(&option);
QMargins m = getPaddingToLabel();
QRect r = option.fontMetrics.boundingRect(0, 0, width() - m.right() - m.left(), 2147483647, mTextFlags, text());
size.setHeight(r.height() + m.top() + m.bottom());
return size;
}
void WrappingPushButton::paintEvent(QPaintEvent* e)
{
QStylePainter p(this);
QStyleOptionButton option;
initStyleOption(&option);
//This will prevent the style from drawing the text
option.text = "";
//Draw button
p.drawControl(QStyle::CE_PushButton, option);
//Draw Text
QMargins m = getPaddingToLabel();
QRect innerRectangle = QRect(m.right(), m.top(), width() - m.right() - m.left(), height() - m.top() - m.bottom());
p.drawText(innerRectangle, mTextFlags, text());
}
QMargins WrappingPushButton::getPaddingToLabel() const
{
//TODO: How to get the real margins!
return QMargins(10,10,10,10);
}
To copy to clipboard, switch view to plain text mode
Bookmarks