skin.qss问题出在哪里?

中才德创 2010-07-15 07:53:59
skin.qss
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****************

用以下代码进行测试,报:Could not parse application stylesheet
#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;
}
...全文
268 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lefttime 2010-07-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 hawkofwinter 的回复:]

为何在skin.qss文件后加上如下disable钮的图,报Could not parse application stylesheet
C/C++ code
*#MyPushButton : !enable
{
border-image : url(./skin/images/pushbutton_disable.png);
}
[/Quote]
又多出一个问题 @@

这个主要是你的语法出现问题了:

*#MyPushButton:!enable /*注意了, 冒号两边是没有空格的*/
{
border-image : url(./skin/images/pushbutton_disable.png);
}
中才德创 2010-07-16
  • 打赏
  • 举报
回复
为何在skin.qss文件后加上如下disable钮的图,报Could not parse application stylesheet
*#MyPushButton : !enable
{
border-image : url(./skin/images/pushbutton_disable.png);
}
mercedes2 2010-07-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 mercedes2 的回复:]

引用 5 楼 hawkofwinter 的回复:

为何在skin.qss文件后加上如下disable钮的图,报Could not parse application stylesheet
C/C++ code
*#MyPushButton : !enable
{
border-image : url(./skin/images/pushbutton_disable.png);
}……
[/Quote]
我觉得用:disable可能会比:!enable好

对了,状态的话应该是:disabled。
mercedes2 2010-07-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 hawkofwinter 的回复:]

为何在skin.qss文件后加上如下disable钮的图,报Could not parse application stylesheet
C/C++ code
*#MyPushButton : !enable
{
border-image : url(./skin/images/pushbutton_disable.png);
}
[/Quote]


我觉得用:disable可能会比:!enable好
lefttime 2010-07-16
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 hawkofwinter 的回复:]

皮肤文件更改成如下,OK了。

另外,有个不解,既然qss文件遵守一定的法则,当前没有一个可以校验它的编程器吗?

好比一个xml文件,用XMLspy打开,按个F7就知晓这个文件的好坏?

XML code
QPushButton
{
color : red
}

*#MyPushButton
{
min-width : 74px;
min-height :……
[/Quote]

呵呵, 很期待有~```
中才德创 2010-07-16
  • 打赏
  • 举报
回复
皮肤文件更改成如下,OK了。

另外,有个不解,既然qss文件遵守一定的法则,当前没有一个可以校验它的编程器吗?

好比一个xml文件,用XMLspy打开,按个F7就知晓这个文件的好坏?

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);
}
中才德创 2010-07-15
  • 打赏
  • 举报
回复
如下就好。
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;
}
lefttime 2010-07-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lefttime 的回复:]

*#MyPushButton
{
min-width : 74px; 加上冒号
min-height : 22px; 加上冒号
border-image : url(./skin/images/pushbutton_normal.png);
border-top : 2px transparent;
border-bottom :……
[/Quote]

汗, 应该是分号~``
lefttime 2010-07-15
  • 打赏
  • 举报
回复
*#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;
}
mercedes2 2010-07-15
  • 打赏
  • 举报
回复
你可以试着打印一下strTemp,看看你的文件读写是否正确

16,213

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧