2 Attachment(s)
[4.1.1] Custom Widget visible in Edit but not in Preview
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:
Code:
// File: an_aus.h
#include "ui_an_aus.h"
#include <QWidget>
{
Q_OBJECT
public:
virtual QSize minimumSizeHint
() const;
private:
Ui::an_aus _ui;
};
Code:
// File: an_aus.cpp
#include "an_aus.h"
#include "ui_an_aus.h"
AnAusWidget
::AnAusWidget(QWidget *parent
){
_ui.setupUi(this);
qDebug("Constructor of Widget was called");
qApp->beep();
}
QSize AnAusWidget
::minimumSizeHint() const {
qDebug("SizeHint was called");
}
The qDebug("Constructor ...") is called twice: start of dragging and after drop in edit mode. But never called in Preview... ?
Code:
// File: an_aus_plugin.h
#ifndef ANAUSPLUGIN_H
#define ANAUSPLUGIN_H
#include <QDesignerCustomWidgetInterface>
{
Q_OBJECT
public:
bool isContainer() const;
bool isInitialized() const;
private:
bool initialized;
};
#endif
Code:
// File: an_aus_plugin.cpp
#include "an_aus_plugin.h"
#include "an_aus.h"
#include <QtPlugin>
AnAusPlugin
::AnAusPlugin(QObject *parent
){
initialized = false;
}
{
if (initialized) return;
initialized = true;
}
bool AnAusPlugin::isInitialized() const
{
return initialized;
}
{
return new AnAusWidget(parent);
}
{
return "AnAus";
}
{
return "Display Widgets [Examples]";
}
QIcon AnAusPlugin
::icon() const {
}
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)
Code:
// 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
Re: [4.1.1] Custom Widget visible in Edit but not in Preview
I am having the same problem. Not sure why? Does anyone have a solution to this problem? My setup is the same .
Re: [4.1.1] Custom Widget visible in Edit but not in Preview
I did some testing, and the custom widgets show when you compile and run a form using the custom widget, it simply doesn't show up in designer->preview
Re: [4.1.1] Custom Widget visible in Edit but not in Preview
You should be seeing two problems here. 1) Any container widget you create should not actually accept items to "contain." 2) All widgets should not work in Preview mode.
Here is the solution. Your widget naming scheme is not consistant.
in you doXml function, you use this:
Code:
return "<widget class=\"AnAus\" name=\"an_aus\">\n"" <property name=\"geometry\">\n"
when in fact it should be
Code:
return "<widget class=\"AnAusWidget\" name=\"AnAus\">\n"" <property name=\"geometry\">\n"
That class name should be the name of the class you are trying to make custom. More specifically, what ever you return in the creatWidget function, you should use here. In your case, you are returning a
Code:
AnAusWidget (parent)
so you class name should be
Code:
<widget class=\"AnAusWidget\"
Your name can be what ever you want, but it has to match what you put in the plugin::name function. You put
So your name in the doXml should be
Finally, you should change this
Code:
Q_EXPORT_PLUGIN2(customwidgetplugin, AnAusPlugin)
to something like this:
Code:
Q_EXPORT_PLUGIN2(AnAus_v1, AnAusPlugin)
Make this as specfic as possible, otherwise Designer gets two of the same plugin "TARGET" names, and can't figure out which one to use.
I made the same exact mistakes, and this was the solution for me.
Re: [4.1.1] Custom Widget visible in Edit but not in Preview
Dear rianquinn,
thank you for your information.
I tried you changes and the did no work. However they brougth me to the right track:
I had to change:
Code:
{
return "AnAusWidget"; // b/c I create a AnAusWidget ... before was: return "AnAus";
}
and in
doXml
Code:
.....
return "<widget class=\"AnAusWidget\" name=\"an_aus\">\n"
.....
instead of
Code:
.....
return "<widget class=\"AnAus\" name=\"an_aus\">\n"
.....
So the main problem was, that I gave the wrong name of the custom widget at these two places.
:o
Thanks again for pointing me in the right direction.
Michael