Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding a .ui file to TabWidget
Forum Updated to NodeBB v4.3 + New Features

Adding a .ui file to TabWidget

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nicky j
    wrote on last edited by
    #1

    Hey all,

    My program I am working on has two .ui files. The first of these (browser.ui) creates a layout with a TabWidget and a button. When I click the button, it adds another tab to the TabWidget. I would like the new tab to be filled with my second ui file (TabContent.ui). How can I do this?

    code:
    browser.cpp:
    @#include "browser.h"
    #include "ui_browser.h"
    #include "ui_TabContent.h"

    browser::browser(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::browser)
    {
    ui->setupUi(this);
    }

    browser::~browser()
    {
    delete ui;
    }

    void browser::on_NewTabButton_clicked()
    {
    !!NEEDS TO BE FILLED WITH TABCONTENT.UI!!

    }
    @

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brcontainer
      wrote on last edited by
      #2

      If I understand what you said, do the following:

      1. Go to QTCreator
      2. In toolbar click in "File"
      3. See: File > New File or Project (or Ctrl+N)
      4. See: Chosse a template > Files and classes > C++ > C++ Class
      5. Now will open a window named "C++ Class Wizard".
      6. In "Class Name:" enter with text: "MyCustomWidget"
      7. In "Base class:" enter with text: "QTabWidget" (or outher widget type)
      8. Click in "Next" > click in "Finish".
      9. 3 files were created: mycustomwidget.h, mycustomwidget.cpp, mycustomwidget.cpp (you must have all 3 files so you can work with other classes)

      your browser.cpp should look like:

      @#include "browser.h"
      #include "ui_browser.h"
      #include "ui_TabContent.h"

      browser::browser(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::browser)
      {
      ui->setupUi(this);
      }

      browser::~browser()
      {
      delete ui;
      }

      void browser::on_NewTabButton_clicked()
      {
      MyCustomWidget *a = new MyCustomWidget(this);//or new MyCustomWidget;
      ui->centralWidget->layout()->addWidget(a);
      }@

      bq. Note: centralWidget is a standard widget in all projects created from scratch

      QT project: https://github.com/brcontainer/qt-helper

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved