QTabBar setTabText and setTabToolTip not working
-
When I tabify QDockWidgets I want to edit the text in the QTabBar for the tabbed docks. I have set the text for one of my QDockWidgets to "F" for texting purposes. The following code extract is inside my MainWindow:
QObjectList oList = children(); QObject *object; QTabBar *tabBar = nullptr; foreach (object, oList) { if (object->metaObject()->className() == "QTabBar") { tabBar = qobject_cast<QTabBar *>(object); break; } } for (int i = 0; i < tabBar->count(); ++i) { if (tabBar->tabText(i) == "F") { tabBar->setTabText(i, "Folders"); // fails tabBar->setTabToolTip(i, "System Folders"); // fails tabBar->setTabTextColor(i, Qt::red); // fails tabBar->setTabIcon(i, QIcon(":/images/icon16/test.png")); // works tabBar->setTabVisible(i, false); // works } }
Any ideas why this if failing?
-
Hi,
What exactly it failing ?
Are you sure you are working on the correct QTabBar ? -
The lines commented // fails are not working. Since the lines:
tabBar->setTabIcon(i, QIcon(":/images/icon16/test.png")); // works tabBar->setTabVisible(i, false); // works
are working, I'm pretty confident I have the correct QTabBar. In addition, a QDebug reported the correct text, which I removed for brevity. Finally, there is only 1 QTabBar in oList.
-
@Rory_1 said in QTabBar setTabText and setTabToolTip not working:
@SGaist Thanks for the link. I'm not seeing how this will help me. Can you give me a hint on how to rename the tab text and set the tooltip in this situation? Much appreciated.
That's what the code shows, you can't as the content of the tab bar is updated based on the QDockWidget, so either you modify the dock widget on docking/undocking or you can try KDDockWidgets. Last option is to build your own qtbase with the modification required to implement what you want.