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?
parseCSV->getDataForEquityType(eqType)
or thedw->displayAnalysis(..)
? And do you really need to call it every time a tab is clicked, or just the first time it is clicked? – thuga