Results 1 to 3 of 3

Thread: How do I add new tab to QTabWidget

  1. #1
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How do I add new tab to QTabWidget

    Sorry if this has been asked already. I just haven't found a related enough thread to point me in the right direction. I have a program that I have coded in C# .NET 3.5 thus far and want to port it to the best of my ability to C++ with Qt 4.4.0. I want to develop a tabbed text editor so that I don't have to deal with MDI windows. It's the start of an IDE for an E-Blah Forum template editor. I have the GUI setup in C# .NET currently. I have the GUI mimicked in Qt Designer and have a QTabWidget already setup there. I'm just trying to figure out how to add a tab to a QTabWidget. I just need to know the correct syntax and class structure.

    I understand that I must have a QTabWidget object to place tabs into, which I have, but how do I add new tabs? Do I need to create a class for each kind of tab to add to the main QTabWidget?

    Here is the code that I have to add a new tab right now:
    Qt Code:
    1. tab = new QTabWidget;
    2. tabDocument->addTab(tab, tr("General"));
    To copy to clipboard, switch view to plain text mode 
    tab is defined here:
    Qt Code:
    1. // defaulttab.h
    2. // Default Tab for tab interface
    3.  
    4. class tab : public QWidget
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. tab(QWidget *parent = 0);
    10. };
    To copy to clipboard, switch view to plain text mode 
    The name tab is just a test. I was trying to get a tab to show up and make it easy for me to do so with a short name.

    With the above code, I don't get a compile error. It seems to all be ok. However, I get a SIGSEGV error when running the event to trigger the addtab method.
    Last edited by pcmantinker; 5th June 2008 at 02:54.

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: How do I add new tab to QTabWidget

    Hi,

    Qt Code:
    1. QWidget *newTab = new QWidget(myTabWidget);
    2. myTabWidget->addTab(newTab, tr("name"));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How do I add new tab to QTabWidget

    Thanks. I appreciate your help.

Similar Threads

  1. Force focus to a QTabWidget page's widget
    By thomaspu in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2008, 07:54
  2. QTabWidget remove a page at the page's request
    By thomaspu in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2007, 21:45
  3. Adding QGroupBox to QTabWidget
    By mclark in forum Newbie
    Replies: 2
    Last Post: 17th January 2007, 17:27
  4. QTabWidget Placement and Display
    By mclark in forum Newbie
    Replies: 1
    Last Post: 16th January 2007, 21:34
  5. Corner widget in QTabWidget doesn't show up
    By ePharaoh in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2006, 18:02

Tags for this Thread

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.