Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get QTabWidget title text of QWidget in Qt?

Tags:

c++

qt

qwidget

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!!
like image 931
Engo Avatar asked Jan 04 '16 23:01

Engo


People also ask

How do I change my Qt tab name?

If so, click on the tab you want to rename, then in the Property Editor (if you can't find it make sure it's visible by using the View->Property Editor menu item) scroll down to the bottom and look for the currentTabText property. You can change the tab's name right there.

How do I use tab widget in Qt?

The normal way to use QTabWidget is to do the following: Create a QTabWidget. Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them. Insert child widgets into the page widget, using layouts to position them as normal.

What is QWidget?

The QWidget class is the base class of all user interface objects. The widget is the atom of the user interface: it receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a Z-order.


1 Answers

int index = ui->tabWidget->currentIndex();
QString currentTabText = ui->tabWidget->tabText(index);
like image 103
DevGuy Avatar answered Sep 29 '22 12:09

DevGuy