How to control a widget which created by UI Designer ?



  • Dear Sirs,

    I put a tabWidget on the MainWindow, this tabWidget is drag and drop from UI designer, so there is no "QTabWidget *tabWidget" declaration on the header file.

    Now I want to add a new tab by code, such as "tabWidget->addTab(button1, "Tab1");".
    Obviously there is no such widget for me to use, because this object is not declared before.

    What should I do ?

    Is there any way to tell compiler to find this object from UI designer ?

    Appreciate for any comments,


  • Moderators

    Hi Hiloshi,

    in your constructor you can use :

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->tabWidget->addTab(button1, "Tab1");"
    }
    

    The ui pointer is your gate to everything you defined in Qt Designer.

    Eddy



  • Dear @Eddy ,

    Yes, I should able do that. Thank you very much.

    Best Regarts,


Log in to reply
 

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