moellney
19th March 2006, 13:11
Fedora Core 3, QT 4.1.1, gcc
Hi!
This is my first start in producing a custom widget: 'AnAusWidget' to use it in Designer 4.1.1.
The 'funny' thing is, that I can see my AnAusWidget in Editor mode, but when I go into preview mode the widget ist not there (kind of). AnAusWidget ist just a Widget produced in Designer holding one Button and a SpinBox with a simple connection between these two.
I tested two things to see, if it is really not there:
1. Into the Widget where I put in the AnAusWidget (by drag'n'drop) I put a QTextEdit above and one below and used VerticalLayout in the Widget to let the QTextEdit widgets expand sizing.
In Edit Mode I can see me AnAusWidget between the the two QTextEdits.
But wenn i go into Preview Mode the two QTextEdits expand into the area, where my AnAusWidget was located before..... is there a problem in the calculation how much space my AnAusWidgets wants?
2. I set the space for my AnAusWidget to FIXED/FIXED with space 200,200. Now in Preview the space is left free between the QTextEdits. Even the ToolTip for my AnAusWidget is show, but the AnAusWidget ist not.
Please see the attached ScreenShots
Please have a look at the code:
// File: an_aus.h
#include "ui_an_aus.h"
#include <QWidget>
class AnAusWidget : public QWidget
{
Q_OBJECT
public:
AnAusWidget(QWidget *parent = 0);
virtual QSize minimumSizeHint () const;
private:
Ui::an_aus _ui;
};
// File: an_aus.cpp
#include "an_aus.h"
#include "ui_an_aus.h"
AnAusWidget::AnAusWidget(QWidget *parent)
: QWidget(parent)
{
_ui.setupUi(this);
qDebug("Constructor of Widget was called");
qApp->beep();
}
QSize AnAusWidget::minimumSizeHint() const
{
return QSize(100,100);
qDebug("SizeHint was called");
}
The qDebug("Constructor ...") is called twice: start of dragging and after drop in edit mode. But never called in Preview... ?
// File: an_aus_plugin.h
#ifndef ANAUSPLUGIN_H
#define ANAUSPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class AnAusPlugin : public QObject , public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
AnAusPlugin(QObject *parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString codeTemplate() 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
// File: an_aus_plugin.cpp
#include "an_aus_plugin.h"
#include "an_aus.h"
#include <QtPlugin>
AnAusPlugin::AnAusPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}
void AnAusPlugin::initialize(QDesignerFormEditorInterfa ce *)
{
if (initialized) return;
initialized = true;
}
bool AnAusPlugin::isInitialized() const
{
return initialized;
}
QWidget *AnAusPlugin::createWidget(QWidget* parent)
{
return new AnAusWidget(parent);
}
QString AnAusPlugin::name() const
{
return "AnAus";
}
QString AnAusPlugin::group() const
{
return "Display Widgets [Examples]";
}
QIcon AnAusPlugin::icon() const
{
return QIcon();
}
QString AnAusPlugin::toolTip() const
{
return "";
}
QString AnAusPlugin::whatsThis() const
{
return "";
}
bool AnAusPlugin::isContainer() const
{
return false;
}
QString AnAusPlugin::domXml() const
{
// return "";
return "<widget class=\"AnAus\" name=\"an_aus\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"toolTip\" >\n"
" <string>AnAusSchalter</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>Nur so mal ein Test "
"wie PLUGINs funktionieren.</string>\n"
" </property>\n"
"</widget>\n";
}
QString AnAusPlugin::includeFile() const
{
return "an_aus.h";
}
QString AnAusPlugin::codeTemplate() const
{
return "";
}
Q_EXPORT_PLUGIN2(customwidgetplugin, AnAusPlugin)
// File: an_aus_plugin.pro
FORMS = an_aus.ui
CONFIG += designer plugin debug_and_release
CONFIG += release
TEMPLATE = lib
HEADERS = an_aus.h \
an_aus_plugin.h
SOURCES = an_aus.cpp \
an_aus_plugin.cpp
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
To compile I used:
qmake an_aus_plugin.pro
make
su -c "make install"
I would be glad about any comment.
Kind regards,
Michael
Hi!
This is my first start in producing a custom widget: 'AnAusWidget' to use it in Designer 4.1.1.
The 'funny' thing is, that I can see my AnAusWidget in Editor mode, but when I go into preview mode the widget ist not there (kind of). AnAusWidget ist just a Widget produced in Designer holding one Button and a SpinBox with a simple connection between these two.
I tested two things to see, if it is really not there:
1. Into the Widget where I put in the AnAusWidget (by drag'n'drop) I put a QTextEdit above and one below and used VerticalLayout in the Widget to let the QTextEdit widgets expand sizing.
In Edit Mode I can see me AnAusWidget between the the two QTextEdits.
But wenn i go into Preview Mode the two QTextEdits expand into the area, where my AnAusWidget was located before..... is there a problem in the calculation how much space my AnAusWidgets wants?
2. I set the space for my AnAusWidget to FIXED/FIXED with space 200,200. Now in Preview the space is left free between the QTextEdits. Even the ToolTip for my AnAusWidget is show, but the AnAusWidget ist not.
Please see the attached ScreenShots
Please have a look at the code:
// File: an_aus.h
#include "ui_an_aus.h"
#include <QWidget>
class AnAusWidget : public QWidget
{
Q_OBJECT
public:
AnAusWidget(QWidget *parent = 0);
virtual QSize minimumSizeHint () const;
private:
Ui::an_aus _ui;
};
// File: an_aus.cpp
#include "an_aus.h"
#include "ui_an_aus.h"
AnAusWidget::AnAusWidget(QWidget *parent)
: QWidget(parent)
{
_ui.setupUi(this);
qDebug("Constructor of Widget was called");
qApp->beep();
}
QSize AnAusWidget::minimumSizeHint() const
{
return QSize(100,100);
qDebug("SizeHint was called");
}
The qDebug("Constructor ...") is called twice: start of dragging and after drop in edit mode. But never called in Preview... ?
// File: an_aus_plugin.h
#ifndef ANAUSPLUGIN_H
#define ANAUSPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class AnAusPlugin : public QObject , public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
AnAusPlugin(QObject *parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString codeTemplate() 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
// File: an_aus_plugin.cpp
#include "an_aus_plugin.h"
#include "an_aus.h"
#include <QtPlugin>
AnAusPlugin::AnAusPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}
void AnAusPlugin::initialize(QDesignerFormEditorInterfa ce *)
{
if (initialized) return;
initialized = true;
}
bool AnAusPlugin::isInitialized() const
{
return initialized;
}
QWidget *AnAusPlugin::createWidget(QWidget* parent)
{
return new AnAusWidget(parent);
}
QString AnAusPlugin::name() const
{
return "AnAus";
}
QString AnAusPlugin::group() const
{
return "Display Widgets [Examples]";
}
QIcon AnAusPlugin::icon() const
{
return QIcon();
}
QString AnAusPlugin::toolTip() const
{
return "";
}
QString AnAusPlugin::whatsThis() const
{
return "";
}
bool AnAusPlugin::isContainer() const
{
return false;
}
QString AnAusPlugin::domXml() const
{
// return "";
return "<widget class=\"AnAus\" name=\"an_aus\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"toolTip\" >\n"
" <string>AnAusSchalter</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>Nur so mal ein Test "
"wie PLUGINs funktionieren.</string>\n"
" </property>\n"
"</widget>\n";
}
QString AnAusPlugin::includeFile() const
{
return "an_aus.h";
}
QString AnAusPlugin::codeTemplate() const
{
return "";
}
Q_EXPORT_PLUGIN2(customwidgetplugin, AnAusPlugin)
// File: an_aus_plugin.pro
FORMS = an_aus.ui
CONFIG += designer plugin debug_and_release
CONFIG += release
TEMPLATE = lib
HEADERS = an_aus.h \
an_aus_plugin.h
SOURCES = an_aus.cpp \
an_aus_plugin.cpp
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
To compile I used:
qmake an_aus_plugin.pro
make
su -c "make install"
I would be glad about any comment.
Kind regards,
Michael