Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved How to control a widget which created by UI Designer ?

    General and Desktop
    2
    3
    571
    Loading More Posts
    • 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.
    • H
      Hiloshi last edited by Hiloshi

      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,

      1 Reply Last reply Reply Quote 0
      • E
        Eddy last edited by

        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

        Qt Certified Specialist
        www.edalsolutions.be

        H 1 Reply Last reply Reply Quote 4
        • H
          Hiloshi @Eddy last edited by

          Dear @Eddy ,

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

          Best Regarts,

          1 Reply Last reply Reply Quote 0
          • First post
            Last post