mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Infrastructure for dynamically loading Qt style plugins from python
This commit is contained in:
parent
3d15f57526
commit
98d308dfcf
@ -1,6 +1,10 @@
|
||||
#include "QProgressIndicator.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStylePlugin>
|
||||
#include <QPluginLoader>
|
||||
#include <QStyle>
|
||||
#include <QApplication>
|
||||
|
||||
QProgressIndicator::QProgressIndicator(QWidget* parent, int size)
|
||||
: QWidget(parent),
|
||||
@ -122,3 +126,22 @@ void QProgressIndicator::paintEvent(QPaintEvent * /*event*/)
|
||||
p.restore();
|
||||
}
|
||||
}
|
||||
|
||||
int load_style(QString &path, QString &name) {
|
||||
int ret = 0;
|
||||
QStyle *s;
|
||||
QPluginLoader pl(path);
|
||||
QObject *o = pl.instance();
|
||||
if (o != 0) {
|
||||
QStylePlugin *sp = qobject_cast<QStylePlugin *>(o);
|
||||
if (sp != 0) {
|
||||
s = sp->create(name);
|
||||
if (s != 0) {
|
||||
s->setObjectName(name);
|
||||
QApplication::setStyle(s);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -91,3 +91,12 @@ private:
|
||||
QColor m_color;
|
||||
};
|
||||
|
||||
/* Utility function that can be used to load a QStyle from a Qt plugin. This is
|
||||
* here so that there is no need to create a separate PyQt plugin just for this
|
||||
* simple functionality.
|
||||
* \param path The full path to the DLL containing the plugin
|
||||
* \param name The name of the style plugin to load
|
||||
* \return 1 if succeeds 0 otherwise. The objectName of the loaded style is set to name
|
||||
*/
|
||||
int load_style(QString &path, QString &name);
|
||||
|
||||
|
@ -6,6 +6,10 @@
|
||||
%Import QtCore/QtCoremod.sip
|
||||
%Import QtGui/QtGuimod.sip
|
||||
|
||||
%ModuleHeaderCode
|
||||
int load_style(QString &path, QString &name);
|
||||
%End
|
||||
|
||||
class QProgressIndicator : QWidget {
|
||||
|
||||
%TypeHeaderCode
|
||||
@ -50,3 +54,6 @@ protected:
|
||||
virtual void paintEvent(QPaintEvent * event);
|
||||
|
||||
};
|
||||
|
||||
int load_style(QString &path, QString &name);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user