16,213
社区成员
发帖
与我相关
我的任务
分享
QPushButton
{
color : red
}
//************MyPushButton begin***************
*#MyPushButton
{
min-width : 74px
min-height : 22px
border-image : url(./skin/images/pushbutton_normal.png);
border-top : 2px transparent;
border-bottom : 2px transparent;
border-right : 2px transparent;
border-left : 2px transparent;
}
//*************MyPushButton end****************
#include <QApplication>
#include <QPushButton>
#include <QApplication>
#include <QFile>
#include <QStyleFactory>
#include <QTextStream>
bool setSkin(QApplication* const app, QString const &skinFile);
int main(int argc, char *argv[])
{
//加载应用程序实例
QApplication app(argc, argv);
//加载主窗口
QWidget *widget = new QWidget();
widget->setFixedSize(300, 300);
widget->move(0, 0);
//加载PushButton
QPushButton *button = new QPushButton("button", widget);
button->setFixedSize(100, 100);
button->move(100, 100);
//加载应用皮肤
setSkin(&app ,"skin.qss");
button->setObjectName("MyPushButton");
//显示主窗口
widget->showNormal();
//循环
return app.exec();
}
bool setSkin(QApplication* const app, QString const &skinFile)
{
QFile file(skinFile);
if (QFile::exists(skinFile) && file.open(QIODevice::ReadOnly))
{
QApplication::setStyle(QStyleFactory::create("Windows"));
QString strTemp;
QTextStream in(&file);
while (!in.atEnd())
{
strTemp.append(in.readLine());
}
file.close();
app->setStyleSheet(strTemp);
}
else
{
#ifdef Q_WS_MAC
qDebug("%s: %s: File does not exist %s... setting mac style...",
__FILE__, __FUNCTION__, qPrintable(skinFile));
app->setStyle(new QMacStyle());
return true;
#else
qDebug("%s: %s: File does not exist or failed to open %s",
__FILE__, __FUNCTION__, qPrintable(skinFile));
return false;
#endif
}
return true;
}
*#MyPushButton:!enable /*注意了, 冒号两边是没有空格的*/
{
border-image : url(./skin/images/pushbutton_disable.png);
}
*#MyPushButton : !enable
{
border-image : url(./skin/images/pushbutton_disable.png);
}
QPushButton
{
color : red
}
*#MyPushButton
{
min-width : 74px;
min-height : 22px;
border-image : url(./skin/images/pushbutton_normal.png);
border-top : 2px transparent;
border-bottom : 2px transparent;
border-right : 2px transparent;
border-left : 2px transparent;
}
*#MyPushButton:!enable
{
border-image : url(./skin/images/pushbutton_disable.png);
}
*#MyPushButton:hover
{
border-image : url(./skin/images/pushbutton_hover.png);
}
*#MyPushButton:pressed
{
border-image : url(./skin/images/pushbutton_pressed.png);
}
*#MyPushButton:focus
{
border-image : url(./skin/images/pushbutton_focus.png);
}
QPushButton
{
color : red
}
*#MyPushButton
{
min-width : 74px;
min-height : 22px;
border-image : url(./skin/images/pushbutton_normal.png);
border-top : 2px transparent;
border-bottom : 2px transparent;
border-right : 2px transparent;
border-left : 2px transparent;
}