Thanks Jacek because you lead me to the victory with your final advise.
I also thanks all other contributors without who I would not be able to realize my first plugin
Just in case if someone else try to make its own widget as a plugin, I write the full code :
FileChooser.h
// FileChooser.h: interface for the CFileChooser class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_)
#define AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <qwidget.h>
class CFileChooser
: public QWidget{
Q_OBJECT
Q_PROPERTY( QString fileName READ fileName WRITE setFileName
) // Constructor / Destructor
public:
CFileChooser
(QWidget* parent
=0,
const char* name
=0);
virtual ~CFileChooser();
// Slots
public slots:
void setFileName( const QString& fn );
private slots:
void chooseFile();
// Signals
signals:
void fileNameChanged( const QString& fn );
// Functions
public:
// Members
private:
};
#endif // !defined(AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_)
// FileChooser.h: interface for the CFileChooser class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_)
#define AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <qwidget.h>
class QLineEdit;
class QPushButton;
class CFileChooser : public QWidget
{
Q_OBJECT
Q_PROPERTY( QString fileName READ fileName WRITE setFileName)
// Constructor / Destructor
public:
CFileChooser(QWidget* parent=0, const char* name=0);
virtual ~CFileChooser();
// Slots
public slots:
void setFileName( const QString& fn );
private slots:
void chooseFile();
// Signals
signals:
void fileNameChanged( const QString& fn );
// Functions
public:
QString fileName() const;
// Members
private:
QLineEdit* lineEdit;
QPushButton* button;
};
#endif // !defined(AFX_FILECHOOSER_H__59B1F80E_2AB6_4FAD_BA4D_DEAA892068B8__INCLUDED_)
To copy to clipboard, switch view to plain text mode
FileChooser.cpp
// FileChooser.cpp: implementation of the CFileChooser class.
//
//////////////////////////////////////////////////////////////////////
#include "FileChooser.h"
#include <qlayout.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qfiledialog.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFileChooser
::CFileChooser(QWidget* parent,
const char* name
){
layout->setMargin(0);
lineEdit
= new QLineEdit(this,
"filechooser_lineedit");
layout->addWidget(lineEdit);
connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SIGNAL(fileNameChanged(const QString&)));
button
= new QPushButton("...",
this,
"filechooser_button");
button->setFixedWidth(button->fontMetrics().width("..."));
layout->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(chooseFile()));
setFocusProxy(lineEdit);
}
CFileChooser::~CFileChooser()
{
}
void CFileChooser::setFileName(const QString& fn)
{
lineEdit->setText(fn);
}
QString CFileChooser
::fileName() const {
return lineEdit->text();
}
void CFileChooser::chooseFile()
{
if( !fn.isEmpty() )
{
lineEdit->setText(fn);
emit fileNameChanged(fn);
}
}
// FileChooser.cpp: implementation of the CFileChooser class.
//
//////////////////////////////////////////////////////////////////////
#include "FileChooser.h"
#include <qlayout.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qfiledialog.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFileChooser::CFileChooser(QWidget* parent, const char* name)
:QWidget(parent, name)
{
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
lineEdit = new QLineEdit(this, "filechooser_lineedit");
layout->addWidget(lineEdit);
connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SIGNAL(fileNameChanged(const QString&)));
button = new QPushButton("...", this, "filechooser_button");
button->setFixedWidth(button->fontMetrics().width("..."));
layout->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(chooseFile()));
setFocusProxy(lineEdit);
}
CFileChooser::~CFileChooser()
{
}
void CFileChooser::setFileName(const QString& fn)
{
lineEdit->setText(fn);
}
QString CFileChooser::fileName() const
{
return lineEdit->text();
}
void CFileChooser::chooseFile()
{
QString fn;
fn = QFileDialog::getOpenFileName(lineEdit->text(), QString::null, this);
if( !fn.isEmpty() )
{
lineEdit->setText(fn);
emit fileNameChanged(fn);
}
}
To copy to clipboard, switch view to plain text mode
Plugin.h
#include <qwidgetplugin.h>
#include <qwidget.h>
class QT_WIDGET_PLUGIN_EXPORT CustomWidgetPlugin : public QWidgetPlugin
{
public:
CustomWidgetPlugin();
QWidget* create
(const QString
& classname,
QWidget* parent
=0,
const char* name
=0);
QString group
(const QString
&) const;
QIconSet iconSet(const QString&) const;
QString includeFile
(const QString
&) const;
QString toolTip
(const QString
&) const;
QString whatsThis
(const QString
&) const;
bool isContainer(const QString&) const;
};
#include <qwidgetplugin.h>
#include <qwidget.h>
class QT_WIDGET_PLUGIN_EXPORT CustomWidgetPlugin : public QWidgetPlugin
{
public:
CustomWidgetPlugin();
QStringList keys() const;
QWidget* create(const QString& classname, QWidget* parent=0, const char* name=0);
QString group(const QString&) const;
QIconSet iconSet(const QString&) const;
QString includeFile(const QString&) const;
QString toolTip(const QString&) const;
QString whatsThis(const QString&) const;
bool isContainer(const QString&) const;
};
To copy to clipboard, switch view to plain text mode
Plugin.cpp
#include "CustomWidgetPlugin.h"
#include ".\\..\\FileChooser\\FileChooser.h"
CustomWidgetPlugin::CustomWidgetPlugin()
:QWidgetPlugin()
{
}
{
list << "CFileChooser";
return list;
}
QWidget* CustomWidgetPlugin
::create(const QString
& key,
QWidget* parent,
const char* name
) {
if( key == "CFileChooser" )
return new CFileChooser(parent, name);
return 0;
}
QString CustomWidgetPlugin
::includeFile(const QString
& feature
) const {
if( feature == "CFileChooser" )
return "filechooser.h";
}
QString CustomWidgetPlugin
::group(const QString
& feature
) const {
if( feature == "CFileChooser" )
return "Input";
}
QIconSet CustomWidgetPlugin::iconSet(const QString& feature) const
{
return QIconSet
( QPixmap("filechooser_pixmap.png"));
}
QString CustomWidgetPlugin
::toolTip(const QString
& feature
) const {
if( feature == "CFileChooser" )
return "File Chooser Widget";
}
QString CustomWidgetPlugin
::whatsThis(const QString
& feature
) const {
if( feature == "CFileChooser" )
return "A widget to choose a file";
}
bool CustomWidgetPlugin::isContainer(const QString& feature) const
{
return FALSE;
}
Q_EXPORT_PLUGIN( CustomWidgetPlugin );
#include "CustomWidgetPlugin.h"
#include ".\\..\\FileChooser\\FileChooser.h"
CustomWidgetPlugin::CustomWidgetPlugin()
:QWidgetPlugin()
{
}
QStringList CustomWidgetPlugin::keys() const
{
QStringList list;
list << "CFileChooser";
return list;
}
QWidget* CustomWidgetPlugin::create(const QString& key, QWidget* parent, const char* name)
{
if( key == "CFileChooser" )
return new CFileChooser(parent, name);
return 0;
}
QString CustomWidgetPlugin::includeFile(const QString& feature) const
{
if( feature == "CFileChooser" )
return "filechooser.h";
return QString::null;
}
QString CustomWidgetPlugin::group(const QString& feature) const
{
if( feature == "CFileChooser" )
return "Input";
return QString::null;
}
QIconSet CustomWidgetPlugin::iconSet(const QString& feature) const
{
return QIconSet( QPixmap("filechooser_pixmap.png"));
}
QString CustomWidgetPlugin::toolTip(const QString& feature) const
{
if( feature == "CFileChooser" )
return "File Chooser Widget";
return QString::null;
}
QString CustomWidgetPlugin::whatsThis(const QString& feature) const
{
if( feature == "CFileChooser" )
return "A widget to choose a file";
return QString::null;
}
bool CustomWidgetPlugin::isContainer(const QString& feature) const
{
return FALSE;
}
Q_EXPORT_PLUGIN( CustomWidgetPlugin );
To copy to clipboard, switch view to plain text mode
Plugin.pro
######################################################################
# Automatically generated by qmake (1.07a) dim. 29. janv. 10:37:16 2006
######################################################################
SOURCES += CustomWidgetPlugin.cpp ../FileChooser/FileChooser.cpp
HEADERS += CustomWidgetPlugin.h ../FileChooser/FileChooser.h
DESTDIR = $(QTDIR)/plugins/designer
TARGET = filechooser
target.path = $$plugins.path
isEmpty(target.path):target.path==$$QT_PREFIX/plugins
INSTALLS += target
TEMPLATE = lib
CONFIG += qt warn_on release plugin
INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
DBFILE = plugin.db
PROJECTNAME = Plugin
LANGUAGE = C++
######################################################################
# Automatically generated by qmake (1.07a) dim. 29. janv. 10:37:16 2006
######################################################################
SOURCES += CustomWidgetPlugin.cpp ../FileChooser/FileChooser.cpp
HEADERS += CustomWidgetPlugin.h ../FileChooser/FileChooser.h
DESTDIR = $(QTDIR)/plugins/designer
TARGET = filechooser
target.path = $$plugins.path
isEmpty(target.path):target.path==$$QT_PREFIX/plugins
INSTALLS += target
TEMPLATE = lib
CONFIG += qt warn_on release plugin
INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
DBFILE = plugin.db
PROJECTNAME = Plugin
LANGUAGE = C++
To copy to clipboard, switch view to plain text mode
Bookmarks