How to index Tab widget contents ?
-
I have successfully build a common form to be used as needed.
The form has "Tab" as main widget.
Since each Tab is "indexed" , I can change desired Tab title using such index.Each and every Tab contains QEditText widget.
How can I build a function to entry a text to the desired Tab and its QEditText?
Is there a way to "index" the QEditText widget in each Tab?
-
@AnneRanch
Each tab has a "page" as its widget. QWidget *QTabWidget::widget(int index) const returns the page/widget for the given tab. If you say that every one of your tabs has aQTextEdit
for its widget, then:QTextEdit *textEdit = qobject_cast<QTextEdit *>(theTabWidget->widget(tabNum)); if (textEdit != nullptr) qDebug() << "Success"; else qDebug() << "Tab number" << tabNum << "does not have a QTextEdit as its (top-level) widget";
So you can then use
QTextEdit *textEdit
as the text edit on tab numbertabNum
.(If by chance your tab pages are actually
QWidget
s --- which might be how they get created in Designer --- which then contain aQTextEdit
we would have to alter the code slightly, but the principle holds.) -
@JonB said in How to index Tab widget contents ?:
QTextEdit *textEdit = qobject_cast<QTextEdit *>(theTabWidget->widget(tabNum));
if (textEdit != nullptr)
qDebug() << "Success";
else
qDebug() << "Tab number" << tabNum << "does not have a QTextEdit as its (top-level) widget";Thanks, but I am little stumped.
Here is my function which basically access the tab, not the containing "page" .
QString MainWindow_C_CODE_FORM::TabTitle(QString text , int index)
{
// change tab title using index TOK
ui->tabWidget->setTabText(index,text);
// access QTextEdit ??
QTextEdit *textEdit = qobject_cast<QTextEdit *>(theTabWidget->widget(tabNum));
if (textEdit != nullptr)
qDebug() << "Success";
else
qDebug() << "Tab number" << tabNum << "does not have a QTextEdit as its (top-level) widget";return text;
}
Can I still modify your code to work in this function?
It does not have to work in the function , I can as well write another one.But I still do not get the access to the "page" .
-
I did try similar approach and it is sort-off working.
Does that makes sense ?MWCCF->centralWidget()->topLevelWidget()->setWindowTitle("TEST windopw TITLE"); MWCCF->centralWidget()->topLevelWidget()->topLevelWidget()->setToolTip("TEST TAB TOOL TIP");
I have not figured out how to actually select desired Tab, so far only " top xyz..." is working.
This approach is little cryptic ,but it would bypass the need for extra sub-funtion...
ADDENDUM
I think the above "topLevel" is OK for ONE level, it doe not makes much sense for multiple level...I like to modify / change my original post.
Is there a way to scan thru the widgets / tabs to find a tab of specific title?
I am still not sure how to find the correct widget - tab for example - pointer.