Hallo,
ich habe versucht ein Cumstom Style Plugin zu erzeugen.
Zuerst habe ich einen Custom Style geschrieben und getestet.
Dann habe ich daraus eine DLL erzeugt und in den Stylewindow Ordner von Styles kopiert, wie es im Handbuch beschrieben wird.
Dann versuchte ich ihn in einem Programm dynamisch zu laden.
Leider änderte sich nichts.
Was könnte ich falschgemacht haben?
Ich habe es erstmal mit ganz einfachen Beispielen aus dem Handbuch versucht:
customstyle.h
//////////////////////////////////////
#include <QtCore>
#include <QtGui>
#include "customstyleplugin.h"
#include "customstyle.h"
QStringList CustomStylePlugin::keys() const
{
return QStringList() << "CustomStyle";
}
QStyle *CustomStylePlugin::create(const QString &key)
{
if (key.toLower() == "customstyle")
return new CustomStyle;
return 0;
}
Q_EXPORT_PLUGIN2(customstyleplugin, CustomStylePlugin)
////////////////////////////////////////////////////////////////////////////
customstyle.cpp
///////////////////////////////////////////////////////////////////////
#include "customstyle.h"
void CustomStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
{
if (element == PE_IndicatorSpinUp || element == PE_IndicatorSpinDown) {
QPolygon points(3);
int x = option->rect.x();
int y = option->rect.y();
int w = option->rect.width() / 2;
int h = option->rect.height() / 2;
x += (option->rect.width() - w) / 2;
y += (option->rect.height() - h) / 2;
if (element == PE_IndicatorSpinUp) {
points[0] = QPoint(x, y + h);
points[1] = QPoint(x + w, y + h);
points[2] = QPoint(x + w / 2, y);
} else { // PE_SpinBoxDown
points[0] = QPoint(x, y);
points[1] = QPoint(x + w, y);
points[2] = QPoint(x + w / 2, y + h);
}
if (option->state & State_Enabled) {
painter->setPen(option->palette.mid().color());
painter->setBrush(option->palette.buttonText());
} else {
painter->setPen(option->palette.buttonText().color());
painter->setBrush(option->palette.mid());
}
painter->drawPolygon(points);
} else {
QWindowsStyle::drawPrimitive(element, option, painter, widget);
}
}
////////////////////////////////////////////////////////////////////////////////
customstyleplugin.h
///////////////////////////////////////////////////////////////////////////////
#ifndef CUSTOMSTYLEPLUGIN_H
#define CUSTOMSTYLEPLUGIN_H
#include <QStylePlugin>
class QStringList;
class QStyle;
class CustomStylePlugin : public QStylePlugin
{
Q_OBJECT
public:
CustomStylePlugin() {};
QStringList keys() const;
QStyle *create(const QString &key);
};
#endif // CUSTOMSTYLEPLUGIN_H
////////////////////////////////////////////////////////////////////////////////
customstyleplugin.cpp
/////////////////////////////////////////////////////////////////////////////////
#include <QtCore>
#include <QtGui>
#include "customstyleplugin.h"
#include "customstyle.h"
QStringList CustomStylePlugin::keys() const
{
return QStringList() << "CustomStyle";
}
QStyle *CustomStylePlugin::create(const QString &key)
{
if (key.toLower() == "customstyle")
return new CustomStyle;
return 0;
}
Q_EXPORT_PLUGIN2(customstyleplugin, CustomStylePlugin)
////////////////////////////////////////////////////////////////////////
Die dll habe ich in den Ordner styles->Stylewindow und später testweise in den Ordner plugins->designer kopiert.
Dann habe ich noch ein Widget mit einer Spinbox geschrieben,
und ein Standard-Main-Program um die folgende Code-Zeile ergänzt:
QApplication::setStyle(QStyleFactory::create("customstyle"));
Hat jemand eine idee?
Probleme mit Custom Style Plugins
Sorry falsche Überschriften
customstyle.h:
#ifndef CUSTOMSTYLE_H
#define CUSTOMSTYLE_H
#include <QtGui>
class CustomStyle : public QWindowsStyle
{
Q_OBJECT
public:
CustomStyle(){}
~CustomStyle() {}
void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const;
};
#endif // CUSTOMSTYLE_H
#ifndef CUSTOMSTYLE_H
#define CUSTOMSTYLE_H
#include <QtGui>
class CustomStyle : public QWindowsStyle
{
Q_OBJECT
public:
CustomStyle(){}
~CustomStyle() {}
void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const;
};
#endif // CUSTOMSTYLE_H
-
Christian81
- Beiträge: 7319
- Registriert: 26. August 2004 14:11
- Wohnort: Bremen
- Kontaktdaten:
Bitte die [
Code: Alles auswählen
]-Tags benutzen - so kann man nichts lesen.MfG Christian
'Funktioniert nicht' ist keine Fehlerbeschreibung
'Funktioniert nicht' ist keine Fehlerbeschreibung
Christian81 hat geschrieben:Bitte die [Code: Alles auswählen
]-Tags benutzen - so kann man nichts lesen.[/quote] Zeigt immer wieder wie schlampig manche Leute arbeiten. Es gibt eine Vorschau-Funktion, aber das ist ja ein Klick mehr und scrollen muss man meist auch noch :-) Schlecht leserliche Posts werden übergangen, die Zeit das zu entziffern nehme ich mir nicht.
Die deutsche Schriftsprache ist case-sensitive. Außerdem gibt es eine Interpunktionsnorm. Wenn manch einer seine Programme genauso schlampig schreibt, wie sein Posting hier, dann sollte er es lieber bleiben lassen.