PDA

View Full Version : [Qt 4.1.0] Split a widget on demand



Townk
17th February 2006, 12:21
Hi all,
I have the following problem:

I have a widget and user could go to menu em choose "Split horizontal" or "Split vertical";
as he do that each splitted widget could be splitted another time and thats all.
So I have this:

+-----------+
| |
| |
| |
+-----------+
than if user split horizontaly he should have this:

+-----+-----+
| | |
| | |
| | |
+-----+-----+
At this point each splitted widget could be splitted one more time but only on vertical. Lets split left widget:

+-----+-----+
| | |
+-----+ |
| | |
+-----+-----+
Ok now that I explain myself, lets to the real problem:
I have a widget that extens QSplitter and on its constructor I add one widget. So far so good...
But when I try to add another widget outside constructor, it not show the new widget and worst, if I try to delete an existen one, the program crashes.

The question is:
How do I add widgets on demand on a QSplitter and how do I delete the existen ones?

zlatko
17th February 2006, 13:22
May we see your code? It will be very helful.

Townk
17th February 2006, 14:07
Its something like this:


class MySplitter : public QSplitter {
public:
MySplitter(QWidget *parent = 0) : QSplitter(parent) {
QTextEdit *editor = new QTextEdit(this);
addWidget(editor);
}

public slots:
void splitHorizontal() {
QTextEdit *editor = new QTextEdit(this);
addWidget(editor);
}
};

this simple code doesn't work!

wysota
17th February 2006, 14:16
Call "editor->show();".