Refactor system page in GUI Alpha.
This commit is contained in:
@@ -16,13 +16,15 @@ void ListBox::paintEvent(QPaintEvent *e) {
|
||||
QStylePainter painter(this);
|
||||
QStyleOptionToolButton opt;
|
||||
initStyleOption(&opt);
|
||||
//在最后绘制按钮的时候将text清空,避免绘制出左对齐的文字
|
||||
opt.text.clear();
|
||||
painter.drawComplexControl(QStyle::CC_ToolButton, opt);
|
||||
//自行绘制居中对齐的文字
|
||||
int x = (size().width() - this->iconSize().width()) / 2 - (this->text().length() * opt.font.pixelSize()) / 4;
|
||||
int y = this->iconSize().height() + 2;
|
||||
painter.drawText(x,y,this->text());
|
||||
|
||||
QFontMetrics fm(opt.font);
|
||||
int textWidth = fm.horizontalAdvance(this->text());
|
||||
int textHeight = fm.height();
|
||||
int x = (size().width() - this->iconSize().width() - textWidth) / 2;
|
||||
int y = (size().height() + textHeight) / 2 - fm.descent();
|
||||
painter.drawText(x, y, this->text());
|
||||
}
|
||||
|
||||
void ListBox::setSmallBox(bool isSmall) {
|
||||
|
||||
Reference in New Issue
Block a user