Возникла проблема - сбилдил кастомную кнопку (все делал как описано в мануале по созданию подобных контролов), закинул ее в плагин директорию (C:\Qt\2010.05\qt\plugins\designer), а дизайнер эту кнопку не подтянул. Что нужно сделать для того,
чтобы кнопка появилась среди контролов дизайнера? Буду очень благодарен за советы и помощь!!
Код ниже:
customButtonTest.proCONFIG += designer plugin debug_and_release
TARGET = $$qtLibraryTarget(custombuttontestplugin)
TEMPLATE = lib
QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer
HEADERS = custombuttontestplugin.h \
custombuttontest.h
SOURCES = custombuttontestplugin.cpp \
custombuttontest.cpp
RESOURCES = icons.qrc
#DEFINES += CustomButtonTest_LIBRARY
#LIBS += -L. -lcustombuttontest
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
customButtonTest.h#ifndef CUSTOMBUTTONTEST_H
#define CUSTOMBUTTONTEST_H
//#include <QtCore/qglobal.h>
#include <QAbstractButton>
#include <QtDesigner/QDesignerExportWidget>
class QMenu;
class QDESIGNER_WIDGET_EXPORT CustomButtonTest : public QAbstractButton
{
Q_OBJECT
public:
explicit CustomButtonTest(QWidget *parent = 0);
QSize sizeHint() const;
void SetMenu(QMenu* i_menu);
void ShowMenu() const;
void AddActions(QList<QAction*> i_actions);
protected:
void paintEvent(QPaintEvent *e);
void mouseReleaseEvent(QMouseEvent* e);
void enterEvent(QEvent*);
void leaveEvent(QEvent*);
private:
bool m_is_active;
QMenu* mp_menu;
};
#endif
customButtonTest.cpp#include "custombuttontest.h"
#include <QMenu>
#include <QPainter>
#include <QtCore>
#include <QMouseEvent>
CustomButtonTest::CustomButtonTest(QWidget *parent) :
QAbstractButton(parent), m_is_active(false)
{}
QSize CustomButtonTest::sizeHint() const
{
return QSize(fontMetrics().width(text()) + 10,
fontMetrics().height() + 10);
}
void CustomButtonTest::SetMenu(QMenu* i_menu)
{
mp_menu = i_menu;
}
void CustomButtonTest::ShowMenu() const
{
qDebug("show menu");
long offset_x = 2, offset_y = 2;//todo magic numbers
QPoint pop_up_point(this->pos().x() - offset_x,
this->pos().y() + height());// + offset_y);
qDebug()<<pop_up_point;
mp_menu->popup(this->mapToGlobal(pop_up_point));//this->mapToGlobal(QPoint(0, 0));
}
void CustomButtonTest::AddActions(QList<QAction*> i_actions)
{
if(!i_actions.isEmpty())
mp_menu->addActions(i_actions);
}
void CustomButtonTest::paintEvent(QPaintEvent* e)
{
qDebug("paint event was occured\n");
QPainter painter(this);
QImage image;
if(m_is_active)
image.load("D:\\private\\dev\\SignatureQt\\imagesload_plan_active.png");
else
image.load("D:\\private\\dev\\SignatureQt\\images\\oad_plan_normal.png");
resize(image.width(), image.height());
painter.drawImage(pos().x(), pos().y(), image);
}
void CustomButtonTest::enterEvent(QEvent*)
{
qDebug("enter\n");
m_is_active = true;
}
void CustomButtonTest::leaveEvent(QEvent*)
{
qDebug("leave\n");
m_is_active = false;
}
void CustomButtonTest::mouseReleaseEvent(QMouseEvent* e)
{
if(e->button() == Qt::LeftButton)
{
qDebug("released\n");
m_is_active = false;
repaint(rect());
if(!mp_menu->isEmpty())
ShowMenu();
}
}
customButtonTestPlugin.h#ifndef CUSTOMBUTTONTESTPLUGIN_H
#define CUSTOMBUTTONTESTPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class Q_DECL_EXPORT CustomButtonTestPlugin : public QObject,
public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit CustomButtonTestPlugin(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 m_initialized;
};
#endif
customButtonTestPlugin.cpp#include "custombuttontest.h"
#include "custombuttontestplugin.h"
#include <QtCore/QtPlugin>
CustomButtonTestPlugin::CustomButtonTestPlugin(QObject *parent)
: QObject(parent)
{
m_initialized = false;
}
void CustomButtonTestPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool CustomButtonTestPlugin::isInitialized() const
{
return m_initialized;
}
QWidget *CustomButtonTestPlugin::createWidget(QWidget *parent)
{
return new CustomButtonTest(parent);
}
QString CustomButtonTestPlugin::name() const
{
return QLatin1String("CustomButtonTest");
}
QString CustomButtonTestPlugin::group() const
{
return QLatin1String("Custom Controls");
}
QIcon CustomButtonTestPlugin::icon() const
{
return QIcon(QLatin1String(":/signature.ico"));
}
QString CustomButtonTestPlugin::toolTip() const
{
return QLatin1String("");
}
QString CustomButtonTestPlugin::whatsThis() const
{
return QLatin1String("");
}
bool CustomButtonTestPlugin::isContainer() const
{
return false;
}
QString CustomButtonTestPlugin::domXml() const
{
return QLatin1String("<widget class=\"CustomButtonTest\" name=\"customButtonTest\">\n</widget>\n");
}
QString CustomButtonTestPlugin::includeFile() const
{
return QLatin1String("custombuttontest.h");
}
Q_EXPORT_PLUGIN2(custombuttontestplugin, CustomButtonTestPlugin)