Results 1 to 6 of 6

Thread: TabWidget

  1. #1
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default TabWidget

    Hi. I've got a tab widget created in designer, and I want one of tab to has a name which is typed in some lineEdit.
    tab - tekst
    lineEdit - tekst

    How to do it?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: TabWidget

    Create a slot in your main window class, called let's say tabNameChanged( const QString& ).

    Connect the line edit's textEdited( const QString& ) to that slot.
    The slot implementation:
    Qt Code:
    1. void MyWindow::tabNameChanged( const QString &text )
    2. {
    3. mTabWidget->setTabText( mTabWidget->currentIndex(), text ).
    4. }
    To copy to clipboard, switch view to plain text mode 

    Please note that this is live update and the text is set only in the current tab. You can play a bit with the code to achieve other results ( update other tab, etc ).

    Regards

  3. #3
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: TabWidget

    Thanks, and I've got a question about it. What's the currentIndex() ? and why we have to make the function const QString? And where (when) should I call this function?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: TabWidget

    Please read the docs. Open Qt Assistant and type in "currentIndex" into the box on the left in the "index" tab. This might clarify some things.

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: TabWidget

    To wysota:
    Open Qt Assistant
    what is Qt Assistant?

    and why we have to make the function const QString?
    It is not "const QString" but "const QString&". This "const" is there to improve performance - you basically tell the compiler that the QString won't be modified inside the function. Normally, the purpose of passing params by reference is to modify them inside the function and not "stress" the stack too much ( like when passing by value ).

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: TabWidget

    Quote Originally Posted by marcel View Post
    To wysota: what is Qt Assistant?
    A funny black box that made me post over 5k times here and over 4k times back at QtForum.

    It is not "const QString" but "const QString&". This "const" is there to improve performance
    That's a side effect. The true effect is that you forbid any changes to the object.

    Normally, the purpose of passing params by reference is to modify them inside the function and not "stress" the stack too much ( like when passing by value ).
    It's not stressing the stack but avoiding the need to copy heavy objects for simple operations. With Qt implicit sharing you can pass parameters by value without a noticable slowdown.

    But in general all that you say is true and my post was only to answer your first question

Similar Threads

  1. tabWidget Question
    By phlash in forum Qt Tools
    Replies: 1
    Last Post: 28th March 2007, 10:54
  2. Adding buttons on the tab part of a tabwidget
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2006, 17:52
  3. how to put the tabbar at the left in a tabwidget
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2006, 06:49
  4. How to open external page link using tabwidget
    By jyoti in forum Qt Programming
    Replies: 2
    Last Post: 13th November 2006, 10:43

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.