PDA

View Full Version : How to change default QTabWidget close button's tooltip text



Fenix Voltres
4th April 2010, 12:33
Hello, simple question:
How can I change the default QTabWidget close button's tooltip text ("Close tab")?
I would like to avoid using Qt Linguist, if it's a solution.

And btw: Happy Easter! :)

tsp
4th April 2010, 17:34
At first I thought that why don't you use QTabWidget::setTabToolTip but then I read your question again and I realised that you want to change the "Close Tab" text to something else. I did not find API method for that functionality and because of that I made a quick-and-dirty "workaround" and I tested it with my own application and it seems that it does the trick i.e. changes the text "Close Tab" to whatever you have defined. Here is my piece of code:



// "tabs" is an instance of QTabWidget
QList<QAbstractButton*> allPButtons = tabs->findChildren<QAbstractButton*>();
for (int ind = 0; ind < allPButtons.size(); ind++) {
QAbstractButton* item = allPButtons.at(ind);
if (item->inherits("CloseButton"))
item->setToolTip("Sulje"); // Default "Close Tab"
}


There are also other buttons like QTableCornerButton and QToolButton inside of QTabWidget that is the reason to go through the whole list and select the ones that are inherits "CloseButton".

Please note that the code above is using internals of the Qt and because of that might not be portable, I tested it with Ubuntu 9.10 where it worked as expected.

Fenix Voltres
5th April 2010, 10:15
Would be great to try yout method, but it seems you forgot to paste it in :P
At least I don't see any piece of code ;)
If there's some modification in Qt source - no problem, in fact I did some other mods already, I just couldn't find exactly what to modify :>

tsp
5th April 2010, 17:15
No I did not forget it, it is still there! It seems that as part of moving Qt Centre to new host (?), code with CODE tags is not visible at least in Firefox :confused:

You can see the message with the code when you select "Reply" and then "Go Advanced" ...

Fenix Voltres
6th April 2010, 00:46
You're absolutely right, something's wrong with FF, indeed.
Thatnks much for code, works great, I'll try to access QTabWidget buttons which are responsible for scrolling tabs also.