How to replace UI labels/tool-tips in Qt application run-time according to context?
We are developing a Qt Desktop application. Application can open multiple files one in each tab, and each tab (file) has its own context. User can open multiple files and switch among these tabs.
e.g. : Like one tab is of Truck management for which action (add_Vehicle) in tool bar should display tool-tip "Add Truck", and if another tab is of Car Management same action should display tool-tip "Add Car".
There are many things like this :
- If I delete truck (i.e. Vehicle from Truck management tab) it should show message box "Truck deleted successfully." and if car (i.e. Vehicle from Car management tab) is deleted "Car deleted successfully" message should be shown.
- There are some dialogs in which texts are directly set to the QLabels through QtDesinger.
How This problem is arised?
Previously the application is supporting only Truck management, Now we are adding support for car management in same application. All messages/UI labels/ Tool-tips are using "Truck". Now We want to change it according to the tab (file) opened.
Feasible thought solution :(Not working at run-time)
All UILabels/ToolTips/Messages are translatable [i.e. written with QObject::tr(..)]. We thought of installing QTranslator according to tab context which will automatically change the texts at all places. Installing QTranslator run-time is not working.
Is there another way of doing this? Or any pointer/hints will be very helpful.
Re: How to replace UI labels/tool-tips in Qt application run-time according to contex
There are different solutions available depending on what classes you use. But essentially everything boils down to either having separate actions (with separate tooltips and status bar tips) for each "context" or to setting tips manually based on the "context" when the "context" changes (e.g. when you switch tabs).
Re: How to replace UI labels/tool-tips in Qt application run-time according to contex
I tried to install QTranslator dynamically (run-time) but it didn't worked, I might have done something wrong.
can't we install QTranslator dynamically (run-time)??
Re: How to replace UI labels/tool-tips in Qt application run-time according to contex
You can install a translator but it won't help you in this situation.
Re: How to replace UI labels/tool-tips in Qt application run-time according to contex
I think it will work if it can translate UILabels/Messages dynamically.
I was thinking to create two translation file "application_Truck_en" (all texts in context of Truck) and "appication_Car_en" (all text in context of car).
On tab switch loading file with appropriate context and installing QTranslator may serve it. (if it translates all texts accordingly at that instant)
But translation of text is not working at run-time apparently (I might be doing something wrong).
What do you think of it? Is it feasible to work this way?
Re: How to replace UI labels/tool-tips in Qt application run-time according to contex
Quote:
Originally Posted by
anwar.qt
I think it will work if it can translate UILabels/Messages dynamically.
I was thinking to create two translation file "application_Truck_en" (all texts in context of Truck) and "appication_Car_en" (all text in context of car).
On tab switch loading file with appropriate context and installing QTranslator may serve it. (if it translates all texts accordingly at that instant)
But translation of text is not working at run-time apparently (I might be doing something wrong).
What do you think of it? Is it feasible to work this way?
The translator doesn't do any magic. You'll have more work switching translations than benefits from using a translator. And what if some day you will really need to translate your application to a different language? The proper way is really to choose from what I offered you. It's not more work than abusing the translation mechanism.
Re: How to replace UI labels/tool-tips in Qt application run-time according to contex
NO I wasn't abusing Translation mechanism, in fact I think its wonderful. I was thinking of it as a easier solution to this problem,but as it turns out its not. Now I will think of some other solution.
Thank you very much for your help. :)