How to get QTabWidget title text of QWidget in Qt?
Asked Answered
W

1

9

I know I can use the widget function of QTabWidget in order to get the the QPlanTextEdit from the specified tab. But how can I get the tab title text of the current tab widget?

QPlainTextEdit* pTextEdit = NULL;
QWidget* pWidget= ui->tabWidget->widget(1);
if (pWidget->metaObject()->className() == "QPlainTextEdit")
    pTextEdit = (QPlainTextEdit*)pWidget;
else
{
    QList<QPlainTextEdit *> allTextEdits = pWidget->findChildren<QPlainTextEdit *>();
    if (allTextEdits.count() != 1)
    { 
        qError() << "Error";
        return;
    }  
    pTextEdit = allTextEdits[0];
}
ptextEdit->setPlainText("Updated Plain Text Edit);
// HERE I NEED THE CURRENT TAB'S TEXT!!
Waistband answered 4/1, 2016 at 23:12 Comment(1)
Are you looking for the text of current tab label? doc.qt.io/qt-4.8/qtabwidget.html#tabTextArgil
D
22
int index = ui->tabWidget->currentIndex();
QString currentTabText = ui->tabWidget->tabText(index);
Dimissory answered 5/1, 2016 at 5:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.