PDA

View Full Version : Custom widget plugin does not show up in editor but does in preview



hansmbakker
13th February 2006, 21:11
Hello everybody,

I have made a custom widget plugin. It consists of a lineedit and a pushbutton. That set is in a horizontal boxlayout, and that layout is in a vertical boxlayout together with a spacer and a textbrowser.

Together they should form a 'chatwindow'.

It loads in designer and when i drag it onto the grid, the embedded widgets shop up. When I drop the widget on the grid, it is an empty rectangle, but when I preview it, it behaves like it should: I see my chatwindow.

Is this normal behavior, or is it possible that I've done something wrong?

Hans

PS.
I also created another plugin which consists of three buttons with icons on them, and they do behave as I expected.

PS. 2
The code of ChatWindow is attached.

hansmbakker
14th February 2006, 14:22
One more problem with this code :confused:

The widget always places itself in the upper-left corner of the window, no matter which place I give it.

Can someone give me some hints about this?

wysota
14th February 2006, 16:31
You have errors in your code...


verticalLayout = new QWidget(parent);

Why do you create a widget in a widget? You should create a vertical layout here and not a widget.

I have changed your code a little:

#ifndef CONNECTIONMANAGER_H
#define CONNECTIONMANAGER_H

#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTextBrowser>
#include <QLineEdit>
#include <QSpacerItem>

class ChatWindow : public QWidget
{
Q_OBJECT

public:
ChatWindow(QWidget *parent = 0);

public slots:
void zetTekst(void);

signals:
void chatBericht(void);

private:

QTextEdit *tekstVak;
QLineEdit *verzendLijn;

QPushButton *verzendKnop;

//opvulling
};

#endif


#include "chatwindow.h"

ChatWindow::ChatWindow(QWidget *parent) : QWidget(parent)
{
QVBoxLayout *lay = new QVBoxLayout;
tekstVak = new QTextBrowser;
verzendLijn = new QLineEdit;
verzendKnop = new QPushButton(tr("Verzenden"));
QHBoxLayout *hlay = new QHBoxLayout;
hlay->addWidget(verzendLijn);
hlay->addWidget(verzendKnop);
lay->addWidget(tekstVak);
lay->addLayout(hlay);
setLayout(lay);
//connect(verzendLijn, SIGNAL(returnPressed()), verzendKnop, SLOT(animateClick()));
connect(verzendKnop, SIGNAL(clicked()), this, SIGNAL(chatBericht()));
}

void ChatWindow::zetTekst()
{
tekstVak->append(tr("Test"));
}

The result attached (BTW. You could have used Designer to make your widget):

hansmbakker
14th February 2006, 16:58
Great!

Thanks for your help

The reason that I made it without Designer was that I'd like to understand what I'm doing, and that I get cleaner code when I don't use Designer.

I want to use these widgets more than once, so I thought it would be the best if I made a plugin from it.

wysota
14th February 2006, 17:11
But if you make them a plugin, you want to use them with Designer, so why not create them with it in the first place?

hansmbakker
14th February 2006, 18:24
The way I did it:

arrange the widgets, spacers and layouts in Designer and then code it manually in a text editor.

How can I easily create plugins with designer, then?
You make a .ui file, compile it with uic, and then?

You have to create the signals and slots , a plugin interface etc and I believe doing that with a texxt editor is the only way.

wysota
14th February 2006, 20:47
arrange the widgets, spacers and layouts in Designer and then code it manually in a text editor.
Well, then you did something wrong, because the code from your class certainly didn't look like copied from Designer. You made some widget and you didn't even put it into a layout (which was why your widget was not visible on the form and not positioned like it should).


How can I easily create plugins with designer, then?
You make a .ui file, compile it with uic, and then?

And then subclass it and write all the necessary code, like for any other widget. I don't see a difference between a regular widget and a widget put into a plugin.


You have to create the signals and slots , a plugin interface etc and I believe doing that with a texxt editor is the only way.

Well... it is not the only way, but even so, it doesn't mean you can't use Designer to design your widgets.

hansmbakker
14th February 2006, 22:08
i use Designer mainly for 'sketching', not for copying the code output

i like the preview feature

wysota
14th February 2006, 22:18
i use Designer mainly for 'sketching', not for copying the code output

Your loss :)

hansmbakker
14th February 2006, 22:21
don't forget i can't program decent in c++, i don't have time to learn it and i'm using qt for only one week now.

wysota
14th February 2006, 23:23
don't forget i can't program decent in c++, i don't have time to learn it and i'm using qt for only one week now.

That's another argument for using Designer and not avoiding it. It generates some of the code for you so that you don't have to do that yourself.

hansmbakker
15th February 2006, 10:55
That's true, but I find it harder to use the designer generated code than code everything myself (strange isn't it :). Its gives me more the idea that I know what I'm doing (I know exactly which things are done which way, and I know all the classes etc), but maybe I'm making it myself too difficult.

It's a pity that there is nobody I know who knows Qt, someone that can sit next to me, someone I can confer with.

wysota
15th February 2006, 11:46
What exactly do you find hard? Maybe we could help you?