如何在Qt中获取QWidget的QTabWidget标题文本?

时间:2016-01-04 23:12:40

标签: c++ qt qwidget

我知道我可以使用QTabWidget的widget功能来从指定的选项卡中获取QPlanTextEdit。但是,如何获取当前选项卡小部件的标签标题文本?

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!!

1 个答案:

答案 0 :(得分:11)

int index = ui->tabWidget->currentIndex();
QString currentTabText = ui->tabWidget->tabText(index);