PDA

View Full Version : Can a Qwidget belong to two different layouts



ioannis
21st May 2009, 11:43
My problem is that I have created a QTextEdit and I want this widget to appear in two different dialogs, so if I change the value in the one layout the value to change in the other layout. Is such a configuration possible?

A minimal example is more than welcome.

Thanks in advance...

Lykurg
21st May 2009, 12:24
Hi,


create two QLineEdits's
connect them using the signal slot mechanism



connect(edit1, SIGNAL(textChanged(const QString&)), edit2, SLOT(setText(const QString&)));
connect(edit2, SIGNAL(textChanged(const QString&)), edit1, SLOT(setText(const QString&)));

EDIT: äh, QTextEdit... The same concept but use textChanged() signal and connect to a custom slot where you change the value of the other edit...

alisami
21st May 2009, 14:03
also it is possible to use one QTextEdit object and change the parent and geometry of the object when needed but that wouldn't be a good solution and it wouldn't be possible to show the two widgets at the same time.

creating two QTextEdit objects makes much sense.

wysota
21st May 2009, 23:29
EDIT: äh, QTextEdit... The same concept but use textChanged() signal and connect to a custom slot where you change the value of the other edit...

There is a nicer solution:


QTextEdit *te1 = new QTextEdit;
QTextEdit *te2 = new QTextEdit;
te2->setDocument(te1->document());

Lykurg
22nd May 2009, 11:29
There is a nicer solution

Wow, of course, I haven't thought of that possibility. Qt is great...