QT按钮图标

 主窗口


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    this->setFixedSize(500,800);
    ui->setupUi(this);

    //显示自定义按钮
    MyButton * btn=new MyButton(":/images/qiDong.jpg");
    btn->setParent(this);
    btn->move(this->width()/2-btn->width()/2,this->height()-300);
    connect(btn,&QPushButton::clicked,this,&MainWindow::dianji);
}

void MainWindow::dianji(){
    qDebug()<<"dian ji";
}

 


自定义按钮类 

MyButton::MyButton(QString path){
pressPath=path;
QPixmap pixmap;
pixmap.load(path);
this->setFixedSize(200,200); //设置大小
this->setStyleSheet("QPushButton{border:0px;}"); //png半透
this->setIcon(QIcon(pixmap)); //设置按钮图标
this->setIconSize(QSize(200,200));
}

FR:徐海涛(hunkxu)

你可能感兴趣的:(qt,java,数据库)