我当前的项目中有几个自定义小部件.我希望将样式表应用到它们中,当我在Qt Creator中这样做时,它似乎有效.但是,在执行程序时,不使用样式表.Qt小部件的样式表正常工作.
有人有建议吗?这是一些相关的代码.
WidgetUnits.h
#ifndef WIDGETUNITS_H
#define WIDGETUNITS_H
#include <QList>
#include <QWidget>
#include <QPainter>
#include <Widgets/JECButton.h>
#include <Unit.h>
#include <Time.h>
namespace Ui
{
class WidgetUnits;
}
class WidgetUnits : public QWidget
{
Q_OBJECT
public:
explicit WidgetUnits(QWidget *parent = 0);
~WidgetUnits();
void setNumTimes(const int& numTimes);
public slots:
void updatePictures(const Time* time);
protected:
void paintEvent(QPaintEvent *event);
private:
void checkNewQueue(const QList<QList<Unit*>*>* units);
Ui::WidgetUnits *ui;
const int pictureWidth; // The width of the Unit pictures.
const int pictureHeight; // The height of the Unit …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,用户点击我的程序的任何小部件(当时是休眠的)并为其选择一种颜色.
然后,此颜色将添加到该特定窗口小部件的样式表中.
但是,当程序结束并再次启动时,我希望该特定小部件保留其样式表.
我不想在每个小部件的样式表中使用硬编码.事实上,我甚至不知道哪个特定的小部件有样式表.
我真正想做的是为应用程序提供一个样式表,并将新颜色编码为单击的特定小部件.
(即:如果用户点击了QPushButton并选择了{color:red}的样式表,
我想只有那个QPushButton是红色的,没有其他的.
所以,如果那个QPushButton的变量名为'Clicky',那就
到QApplications样式表我想补充
一句:'QPushButton#Clicky {color:red}')
要做到这一点,而不必为每个小部件硬编码,
我必须以某种方式将我的PyQt4小部件的变量名称转换为字符串.
我怎样才能做到这一点?
谢谢!
(我已经读过从它们的值中获取python变量名称是非常困难的;
是否可以将任何其他形式的ID添加到样式表中?)
PyQt4
python 2.7.2
Windows 7