之前Blog里面有關於QWT的編譯、配置、使用的文章,分別是在VS與Creator下進行的。

編號 |
函數 |
返回值描述 |
1 |
name() |
提供了插件的類名稱 |
2 |
group() |
該控件所屬的組中的Qt Designer的小工具盒 |
3 |
toolTip() |
一個簡短的說明,以幫助用戶識別Qt Designer中的部件 |
4 |
whatsThis() |
為Qt Designer用戶設計的部件一個較長的描述 |
5 |
includeFile() |
頭文件必須包含在使用該插件的應用程序的。此信息存儲在UI文件中,並將由UIC創建用於包含自定義插件形式的代碼合適的#includes語句。 |
6 |
icon() |
Qt Designer的插件箱中小窗口的圖標 |
7 |
isContainer() |
true表示部件將用來保存子部件,否則為false |
8
9
10 |
createWidget()
domXml()
codeTemplate() |
一個指向自定義窗口小部件的QWidget指針實例,構建了所提供的父母。 注:createWidget()是一個工廠方法,只負責創建小部件的功能。自定義窗口小部件的屬性將不可用,直到load()返回。
描述了部件的屬性,例如:對象名稱、大小提示,以及其它標准的QWidget屬性的描述。
這個函數是預留給Qt Designer將來使用的 |
編號 |
函數 |
返回值描述 |
11 |
initialize() |
設置了自定義窗口部件擴展等功能。自定義容器擴展(見QDesignerContainerExtension)和任務菜單擴展(見QDesignerTaskMenuExtension)應在此函數中設置。 |
12 |
isInitialized() |
如果該部件已被初始化,則返回true;否則返回false。重新實現通常檢查initialize()函數是否已被調用,並返回本次測試的結果。 |
|
...
" \n"
" \n"
" 0\n"
" 0\n"
" 100\n"
" 100\n"
" \n"
" \n"
...
displayname="MyWidget">
widgets::MyWidget
addPage
屬性 | 呈現形式 | 值 | 內容 |
---|---|---|---|
language |
可選項 | "c++", "jambi" |
這個屬性指定了自定義窗口部件提供的語言。 主要有防止C++插件出現在Qt Jambi中。 |
displayname |
可選項 | 類名 | 屬性的值將出現在小工具框,可以用來剝去命名空間。 |
屬性 | 呈現形式 | 值 | 內容 |
---|---|---|---|
name |
必須的 | 該屬性的名稱 | |
type |
必須 | 見下表 | 該屬性的值決定了屬性編輯器將如何處理它們。 |
notr |
可選項 | "true", "false" |
如果屬性是“true”,則該值意味着不再被翻譯。 |
值 | 類型 |
---|---|
"richtext" |
富文本 |
"multiline" |
多行純文本 |
"singleline" |
單行純文本 |
"stylesheet" |
一個CSS樣式表 |
"objectname" |
對象名稱(受限制的一組有效字符) |
"url" |
URL、文件名. |
#CONFIG += designer plugin debug_and_release
#TARGET = $$qtLibraryTarget($$TARGET)
#TEMPLATE = lib
#QT += svg
#QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
CONFIG += plugin
CONFIG += designer
CONFIG += debug_and_release
TEMPLATE = lib
QT += svg widgets designer
HEADERS = qled.h \
qledplugin.h
SOURCES = qled.cpp \
qledplugin.cpp
RESOURCES = qled.qrc
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target sources
# install
#target.path = $$[QT_INSTALL_PLUGINS]/designer
#sources.files = $$SOURCES $$HEADERS *.pro
#sources.path = $$[QT_INSTALL_EXAMPLES]/designer/qledplugin
#INSTALLS += target sources
#ifndef QLED_H #define QLED_H #include <</span>Qt> #include <</span>QWidget> #include <</span>QtDesigner/QDesignerExportWidget> class QColor; class QSvgRenderer; class QDESIGNER_WIDGET_EXPORT QLed : public QWidget { Q_OBJECT Q_ENUMS (ledColor) Q_ENUMS (ledShape) Q_PROPERTY(bool value READ value WRITE setValue); Q_PROPERTY(ledColor onColor READ onColor WRITE setOnColor); Q_PROPERTY(ledColor offColor READ offColor WRITE setOffColor); Q_PROPERTY(ledShape shape READ shape WRITE setShape) public: QLed(QWidget *parent = 0); virtual ~QLed(); bool value() const { return m_value; } enum ledColor { Red=0,Green,Yellow,Grey,Orange,Purple,Blue }; enum ledShape { Circle=0,Square,Triangle,Rounded}; ledColor onColor() const { return m_onColor; } ledColor offColor() const { return m_offColor; } ledShape shape() const { return m_shape; } public slots: void setValue(bool); void setOnColor(ledColor); void setOffColor(ledColor); void setShape(ledShape); void toggleValue(); protected: bool m_value; ledColor m_onColor, m_offColor; int id_Timer; ledShape m_shape; QStringList shapes; QStringList colors; void paintEvent(QPaintEvent *event); private: QSvgRenderer *renderer ; }; #endif
#include
#include
#include
#include
#include
#include
#include "qled.h"
QLed::QLed(QWidget *parent)
: QWidget(parent)
{
m_value=false;
m_onColor=Red;
m_offColor=Grey;
m_shape=Circle;
shapes << ":/resources/circle_" << ":/resources/square_" << ":/resources/triang_" << ":/resources/round_";
colors << "red.svg" << "green.svg" << "yellow.svg" << "grey.svg" << "orange.svg" << "purple.svg" << "blue.svg";
renderer = new QSvgRenderer();
}
QLed::~QLed() {
delete renderer;
}
void QLed::paintEvent(QPaintEvent *)
{
QString ledShapeAndColor;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
ledShapeAndColor=shapes[m_shape];
if(m_value)
ledShapeAndColor.append(colors[m_onColor]);
else
ledShapeAndColor.append(colors[m_offColor]);
renderer->load(ledShapeAndColor);
renderer->render(&painter);
}
void QLed::setOnColor(ledColor newColor)
{
m_onColor=newColor;
update();
}
void QLed::setOffColor(ledColor newColor)
{
m_offColor=newColor;
update();
}
void QLed::setShape(ledShape newShape)
{
m_shape=newShape;
update();
}
void QLed::setValue(bool value)
{
m_value=value;
update();
}
void QLed::toggleValue()
{
m_value=!m_value;
update();
}
#ifndef CUSTOMWIDGETPLUGIN_H #define CUSTOMWIDGETPLUGIN_H #include <</span>QDesignerCustomWidgetInterface>
class QLedPlugin : public QObject, public QDesignerCustomWidgetInterface { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface" FILE "QLedPlugin.json") Q_INTERFACES(QDesignerCustomWidgetInterface) public: QLedPlugin(QObject *parent = 0); bool isContainer() const; bool isInitialized() const; QIcon icon() const; QString domXml() const; QString group() const; QString includeFile() const; QString name() const; QString toolTip() const; QString whatsThis() const; QWidget *createWidget(QWidget *parent); void initialize(QDesignerFormEditorInterface *core); private: bool initialized; }; #endif
#include "qled.h" #include "qledplugin.h" #include <</span>QtPlugin> QLedPlugin::QLedPlugin(QObject *parent) : QObject(parent) { initialized = false; } void QLedPlugin::initialize(QDesignerFormEditorInterface * ) { if (initialized) return; initialized = true; } bool QLedPlugin::isInitialized() const { return initialized; } QWidget *QLedPlugin::createWidget(QWidget *parent) { return new QLed(parent); } QString QLedPlugin::name() const { return "QLed"; } QString QLedPlugin::group() const { return "Led Widgets"; } QIcon QLedPlugin::icon() const { return QIcon(":resources/qled.png"); } QString QLedPlugin::toolTip() const { return tr("Led Custom widget Plugin fot Qt Designer"); } QString QLedPlugin::whatsThis() const { return tr("Led Custom widget Plugin fot Qt Designer"); } bool QLedPlugin::isContainer() const { return false; } QString QLedPlugin::domXml() const { return "\n" " \n" " \n" " 0\n" " 0\n" " 50\n" " 50\n" " \n" " \n" " \n" " Binary Led\n" " \n" " \n" " false\n" " \n" " \n" " Led widget\n" " \n" " \n" " QLed::Red\n" " \n" " \n" " QLed::Grey\n" " \n" " \n" " QLed::Circle\n" " \n" "\n"; } QString QLedPlugin::includeFile() const { return "qled.h"; }

QT += core gui svg
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TestCustomWidgetPlugin
TEMPLATE = app
INCLUDEPATH += $$(QTDIR)/include/QCustomWidgetPlugin
INCLUDEPATH += $$(QTDIR)/include/QLed
LIBS += $$(QTDIR)/lib/customwidgetplugin.lib \
$$(QTDIR)/lib/qledplugin.lib
SOURCES += main.cpp\
widget.cpp
HEADERS += widget.h
FORMS += widget.ui
