Set label text in QTabWidget tab
Asked Answered
G

3

46

I have QTabWidget on my form and two tabs on it. These tabs have standard text Tab1 and Tab2. How can I change it?

Gabbert answered 22/3, 2010 at 5:1 Comment(0)
S
76

It sounds like you're talking about Qt Designer, since it defaults to showing two tabs (called "Tab 1" and "Tab 2") when you add a QTabWidget through the interface.

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.

Shipentine answered 22/3, 2010 at 5:10 Comment(4)
Is there a method to set it at runtime, did not see oneShakta
As "none" points out, you cannot choose the tab with the View->"Object Inspector", you have to select the tab in the Edit->"Edit Widgets" view. Poor design if you ask me, but that is how it is...Leadbelly
The currentTabText property is on the QTabWidget and not the individual widgets representing each tab.Fantom
Select the parent QTabWidget in Object Inspector. First select the "currentIndex" corresponding to the tab you would like to alter and hit enter. Change the name using the currentTabText property. Continue doing this for all indexes 0-n.Haynes
J
31

You can use this at runtime:

ui->tabWidget->setTabText(index, "New tab title");
Josefajosefina answered 7/9, 2012 at 11:54 Comment(0)
O
17

In Qt Creator/Designer (2.4.1), if you can't seem to find the currentTabText property, you have probably selected the tab itself in the the object tree.

Make sure to select the QTabWidget, which should happen automatically when selecting the tab in the form preview (see richardwb's answer).

Olmos answered 5/10, 2012 at 9:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.