1. 程式人生 > >QT之滑鼠滑過按鈕,按鈕改變顏色,離開之後,按鈕恢復原先顏色

QT之滑鼠滑過按鈕,按鈕改變顏色,離開之後,按鈕恢復原先顏色

#include "analysis.h"
#include<QEvent>
Analysis::Analysis(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
button1 = new MyButton(this);
button2 = new MyButton(this);
toolButton = new QToolButton(this);
QPixmap pixmap;
pixmap.load("images/arrow_view-analysis.png");
toolButton->setIcon(pixmap);
toolButton->setIconSize(pixmap.size());
toolButton->setText(QStringLiteral("請選擇分類"));
toolButton->setGeometry(200, 100, 100, 40);
toolButton->setStyleSheet("border:1px groove gray;border-radius:3px;background-color:rgb(17,17,17);");
QPalette pal;
pal.setColor(QPalette::ButtonText, QColor(255, 255, 255));
toolButton->setPalette(pal);


button1->setText(QStringLiteral("支架"));
button1->setGeometry(200, 140, 100, 40);
button1->setStyleSheet("background-color:rgb(17,17,17);");
button1->setObjectName("btn1");
button1->setPalette(pal);


button2->setText(QStringLiteral("輪廓"));
button2->setGeometry(200, 180, 100, 40);
button2->setObjectName("btn2");
button2->setStyleSheet("background-color:rgb(17,17,17);");
button2->setPalette(pal);

button1->hide();
button2->hide();
connect(toolButton, SIGNAL(clicked()), this, SLOT(chooseMenu()));
connect(button1, SIGNAL(clicked()), this, SLOT(chooseBtn()));
connect(button2, SIGNAL(clicked()), this, SLOT(chooseBtn()));
}

Analysis::~Analysis()
{

}
void Analysis::chooseMenu()
{
if (!flag)
{
button1->show();
button2->show();
}
}