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. [SOLVED] Load content into tab at runtime on click using QTabWidget
Forum Update on Monday, May 27th 2025

[SOLVED] Load content into tab at runtime on click using QTabWidget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 983 Views
  • 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.
  • P Offline
    P Offline
    PersianMG
    wrote on 25 May 2015, 12:59 last edited by PersianMG
    #1

    This has also been posted here: http://stackoverflow.com/questions/30438887/load-content-into-tab-at-runtime-on-click-using-qtabwidget

    So I have this code in a file AnalysisDisplays.cpp

    void AnalysisDisplays::showAnalysisDisplays(QWidget *parent) {

    QMainWindow *mw = new QMainWindow(parent);
    
    mw->setWindowTitle("Equity Strategy Analysis");
    mw->setMinimumSize(750, 700);
    
    QTabWidget *tabw = new QTabWidget(mw);
    mw->setCentralWidget(tabw);
    
    for (QListWidgetItem *wi: listItems) {
        if (wi->checkState()) {
            std::string eqType = wi->text().toStdString();
    
            DisplayAnalysis *dw = new DisplayAnalysis();
    
            displays[currentDisplayId] = dw;
    
            //Add this tab to tab widget
            tabw->addTab(dw, eqType.c_str());
    
            dw->setDisplayId(currentDisplayId);
            currentDisplayId++;
    
            //dw->displayAnalysis(parseCSV->getDataForEquityType(eqType));
        }
    }
    
    //Show the main window
    mw->show();
    

    }
    The issue is that we may create many tabs which is super slow. The commented out line is what I want to run at runtime. The issue is I am currently making a QMainWindow and a QTabWidget and forgetting about it. I need to somehow hook an event to the QTabWidget so whenever a tab object (DisplayAnalysis) dw is clicked, it will call dw->displayAnalysis(parseCSV->getDataForEquityType(eqType)); where eqType is the title of the tab. This will result in the tab content being populated.

    There can be multiple windows open that call showAnalysisDisplays and they may contain different number of tabs. So each window has its own QMainWindow and QTabWidget but the parseCSV pointer remains the same.

    So how can I hook an event to each tab like this, taking into account that there may be multiple windows open which need to load content at runtime when a tab is clicked?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jakob
      wrote on 25 May 2015, 13:14 last edited by
      #2

      The QTabWidget has a currentChanged signal - my first guess would be to create a slot that connects to that? Inside the slot you should be able to do currentWidget()->displayAnalysis(parseCSV->getDataForEquityType(eqType));

      P 1 Reply Last reply 25 May 2015, 14:12
      0
      • J Jakob
        25 May 2015, 13:14

        The QTabWidget has a currentChanged signal - my first guess would be to create a slot that connects to that? Inside the slot you should be able to do currentWidget()->displayAnalysis(parseCSV->getDataForEquityType(eqType));

        P Offline
        P Offline
        PersianMG
        wrote on 25 May 2015, 14:12 last edited by
        #3

        @Jakob Thanks this worked for me when combined with a solution posted on Stackoverflow! Thanks again!

        1 Reply Last reply
        0

        1/3

        25 May 2015, 12:59

        • Login

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