解决兼容性问题

This commit is contained in:
Mike Solar
2023-08-21 15:10:19 +08:00
parent 5ec58b3bfb
commit 9ee232cead
9 changed files with 110 additions and 55 deletions

View File

@ -6,7 +6,6 @@
MiniButton::MiniButton(QString orig_name, QString op, QWidget* parent)
{
this->orig_name = orig_name;
q_color.setNamedColor(DEFAULT_BACKGROUND_COLOR);
this->op = op;
connect(this, &MiniButton::click, this, &MiniButton::onclick2);
@ -15,11 +14,6 @@ MiniButton::MiniButton(ButtonStruct button_struct, QWidget *parent)
: QPushButton(parent)
{
ui.setupUi(this);
q_color.setNamedColor(DEFAULT_COVER_COLOR);
QString style_sheet = "MiniButton:{background-color:";
style_sheet += DEFAULT_TEXT_COLOR;
style_sheet += ";}";
setStyleSheet(style_sheet);
connect(this, &MiniButton::click, this, &MiniButton::onclick1);
this->button_struct = button_struct;
}
@ -33,14 +27,15 @@ void MiniButton::paintEvent(QPaintEvent* event)
setContentsMargins(0, 0, 0, 0);
QRect rect(0, 0, this->width(), this->height());
QPainter painter(this);
q_color.setNamedColor(background_color);
painter.fillRect(rect, q_color);
int text_x = (width() - TEXT_SIZE * text().length() * scale * 3) / 2;
int text_y = (height()- TEXT_SIZE * scale * 3)/2;
QFont ft;
ft.setPixelSize(TEXT_SIZE);
QRectF text_rect(text_x, text_y, TEXT_SIZE * text().length() * scale * 3, TEXT_SIZE * scale * 3);
painter.setPen(DEFAULT_TEXT_COLOR);
painter.setPen(text_color);
painter.drawText(text_rect, Qt::AlignCenter, text());
}