PDA

View Full Version : [SOLVED: Thanks Jacek] setParent on object just makes it disapear.



hickscorp
6th December 2006, 20:54
Hello people,

i'm new to this forum, i don't know how much active it is.
So let me explain what i'm doing first:
- I want to achieve a very simple text editor (Tab based) like GEdit is.
- I want it to be light (Because it is part of a much bigger project i have).

So for this
- In the first tab i have a QTextEdit item.
- i have created a simple QT Window, with in it a tabContainer.
- In this tab container, i have created two test tabs (tabFile_New1 and tabFile_New2).
- The signal fom the tab container: currentChanged(QWidget*) is handled in my main Window code, and it pretty much does something like this:

void CWndMainImpl::EditorTabChanged (QWidget* pWidget) {
QTabWidget* pSelectedTab = (QTabWidget*)pWidget;
pTextViewer->setParent(pSelectedTab);
}

So as you understood, the goal is to only have one single text edit box which travels from one tab to another, just changing it's content in a transparent way to the end user...

The problem is that when i run the app and then switch from the default tab (Where there is actually the text edit) to the other tab, it doesn't switches. And then when i go back to the original tab, my text edit isn't there anymore...

I have tried very much variants and i don't finally understand what i am doing wrong.

Thanks for your time!
Pierre.

[EDIT:] Sorry for my bad english

jacek
6th December 2006, 21:08
i don't know how much active it is.
Just take a look around and judge for yourself.


QTabWidget* pSelectedTab = (QTabWidget*)pWidget;
Are you sure this cast is correct? QTabWidget doesn't represent a single tab, but the whole tab container.

Maybe you need only QTabBar?

BTW. Which Qt version do you use?

hickscorp
6th December 2006, 21:19
Hello Jacek,

You are right the cast was incorrect (Because it was one of my tests...).
So here is the method which *should* work:

void CWndMainImpl::EditorTabChanged (QWidget* pWidget) {
pTextViewer->setParent(pWidget);
}

But it does the same :(
The interesting point is that when i create my text box, i do as follows:

pTextViewer = new QTextEdit;
pTextViewer->setParent(tabFile_New1);
connect( tabCtnrEditor, SIGNAL(currentChanged(QWidget*)), this, SLOT(EditorTabChanged(QWidget*)) );

And the parent i give is ok.
But then once the parent is set up, if i try to change the edit box's parent, it doesn't works as i'm expecting.

[EDIT:] The version i'm using is QT 4.2, i don't know the minor version (Standard Edgy package).

Anyway, thanks a lot for your help.
Pierre.

jacek
6th December 2006, 21:36
Try this:
void CWndMainImpl::EditorTabChanged (QWidget* pWidget) {
pTextViewer->setParent(pWidget);
pTextViewer->show();
}
But IMO you should use only QTabBar instead of the whole QTabWidget.

hickscorp
6th December 2006, 21:49
Hey, the show() method worked!
I clearly don't understand the "why" but i thanks you a lot for the "how" :)

About using a QTabBar, i don't understand the difference on what i'm doing ?
My problem is that i'm writing code on a derivated class from a ui_* generated by QTDesigner... And i'm not sure if i can place a QTabBar within QTDesigner in the right place, between the right spacers :)

Anyway thanks again, i'll try a lookup at the trolltech docs on how to use QTabBar.

Pierre.

jacek
6th December 2006, 22:27
About using a QTabBar, i don't understand the difference on what i'm doing ?
In short: QTabWidget == QTabBar + QStackedWidget, but clearly you don't want to use QStackedWidget part, so the only thing left is QTabBar ;)

hickscorp
6th December 2006, 22:44
I see, i'll try to look closer at this option.

Thanks for the answers!
Pierre.