Results 1 to 7 of 7

Thread: [SOLVED: Thanks Jacek] setParent on object just makes it disapear.

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default [SOLVED: Thanks Jacek] setParent on object just makes it disapear.

    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:
    Qt Code:
    1. void CWndMainImpl::EditorTabChanged (QWidget* pWidget) {
    2. QTabWidget* pSelectedTab = (QTabWidget*)pWidget;
    3. pTextViewer->setParent(pSelectedTab);
    4. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by hickscorp; 6th December 2006 at 21:49.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setParent on object just makes it disapear.

    Quote Originally Posted by hickscorp View Post
    i don't know how much active it is.
    Just take a look around and judge for yourself.

    Quote Originally Posted by hickscorp View Post
    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?

  3. #3
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setParent on object just makes it disapear.

    Hello Jacek,

    You are right the cast was incorrect (Because it was one of my tests...).
    So here is the method which *should* work:
    Qt Code:
    1. void CWndMainImpl::EditorTabChanged (QWidget* pWidget) {
    2. pTextViewer->setParent(pWidget);
    3. }
    To copy to clipboard, switch view to plain text mode 

    But it does the same
    The interesting point is that when i create my text box, i do as follows:
    Qt Code:
    1. pTextViewer = new QTextEdit;
    2. pTextViewer->setParent(tabFile_New1);
    3. connect( tabCtnrEditor, SIGNAL(currentChanged(QWidget*)), this, SLOT(EditorTabChanged(QWidget*)) );
    To copy to clipboard, switch view to plain text mode 

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setParent on object just makes it disapear.

    Try this:
    Qt Code:
    1. void CWndMainImpl::EditorTabChanged (QWidget* pWidget) {
    2. pTextViewer->setParent(pWidget);
    3. pTextViewer->show();
    4. }
    To copy to clipboard, switch view to plain text mode 
    But IMO you should use only QTabBar instead of the whole QTabWidget.

  5. #5
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setParent on object just makes it disapear.

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setParent on object just makes it disapear.

    Quote Originally Posted by hickscorp View Post
    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

  7. The following user says thank you to jacek for this useful post:

    hickscorp (6th December 2006)

  8. #7
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [SOLVED: Thanks Jacek] setParent on object just makes it disapear.

    I see, i'll try to look closer at this option.

    Thanks for the answers!
    Pierre.
    Last edited by hickscorp; 6th December 2006 at 23:10.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.