[solved]Need help with adding tabs in QTabWidget.

  • I have main window with tabwidget. As I start program I have one tab with some objects.
    I tried make new tab this way:
    void MainWindow::addTab(){
    ui->tabWidget->addTab(new MainWindow(),"Download"+QByteArray::number(ui->tabWidget->count()+1));
    but I noticed a problem, this way I use all parts of MainWindow in new tab even with menu bar and tabwidget (QTabWidget). So I have to take only tab components and use it in another tab but I can't figure out how. All its content is in ui->tab and I want take it and use to make new tab. (I have made ui with .ui file via Qt designer)
    How can I use it? Any hint? Thanks.

  • Don't understand exactly what your problem is, but just as a guess:

    the menu bar in QMainWindow exists independent on the widgets you show in the main area part of QMainWindow. So, when changing the tab in the QTabWidget you clearly see the menu bar. If you don't need this menu bar and the functionality of QMainWindow at all, start with a "Widget" and not with a "Main Window" in Designer and put your QTabWidget there.

  • This is how the first tab looks and also each one should:

    !http://img132.imageshack.us/img132/7224/screenshotdownloaderdl1.png(First tab)!

    And here is second tab I want to look like the first but don't know how:
    !http://img255.imageshack.us/img255/6316/screenshotdownloaderdl2.png(Second tab)!

    My problem is I've already done all functions for my downloader (not 100% but almost) and now I want make tabs (I should've done it by start but I thought it'll be easier at the end).

  • Create a new widget, let's say DownloadSettingsWidget, that containts all the stuff you have now in you first tab. When creating a new tab, create a new DownloadSettingsWidget:

    void MainWindow::addTab(){
    ui->tabWidget->addTab(new DownloadSettingsWidget(), "Download"+QByteArray::number(ui->tabWidget->count()+1));

    So, you application basically consists of a QMainWindow with a tab widget as the main widget plus an additional widget that is dynamically created on demand and put to a new tab.

  • I checked the ui_mainwindow.h generated from mainwindow.ui and whole ui is created in one function so I'll have to remake it, I'll put widget out to other file and use it as separate widget.
    Thanks for help.

    I'll do it tomorrow and if everything will work right I'll mark this as solved.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.