OfficeAssistant_Win10/MyButton.cpp

35 lines
953 B
C++

//
// Created by HW on 2023/07/26.
//
#include "MyButton.h"
MyButton::MyButton(QString logo,QString text,int width,int height,QWidget *parent) : QPushButton(parent) {
this->width2=width;
this->height2=height;
this->text=text;
this->logo=new QImage;
this->logo->load(logo);
this->setStyleSheet("background-color:#333332;");
}
MyButton::~MyButton() {
delete logo;
}
void MyButton::paintEvent(QPaintEvent *e) {
QPushButton::paintEvent(e);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
int logo_width=width()/2;
int logo_x=width()/4;
QFont ft;
ft.setPixelSize(7);
int text_x=0;
int text_y=(logo_width+logo_x);
QRectF logo_rect(logo_x, logo_x, logo_width, logo_width);
QRectF text_rect(text_x,text_y,7*text.length(),7);
painter.setPen(QColor("#FFFFFF"));
painter.drawImage(logo_rect, *logo);
painter.drawText(text_rect, Qt::AlignCenter, text);
}