Results 1 to 7 of 7

Thread: How to replace UI labels/tool-tips in Qt application run-time according to context?

  1. #1
    Join Date
    Sep 2012
    Location
    Pune, India
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question 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 :


    1. 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.

    2. 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2012
    Location
    Pune, India
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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)??

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2012
    Location
    Pune, India
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to replace UI labels/tool-tips in Qt application run-time according to contex

    Quote Originally Posted by anwar.qt View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    anwar.qt (6th February 2013)

  8. #7
    Join Date
    Sep 2012
    Location
    Pune, India
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

Similar Threads

  1. Replies: 0
    Last Post: 10th July 2012, 14:43
  2. Replies: 1
    Last Post: 4th December 2011, 15:58
  3. Load Testing Tool for client server application
    By live_07 in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2009, 19:19
  4. Third Party tool for deploy Qt Application on Mac?
    By vishal.chauhan in forum Qt-based Software
    Replies: 6
    Last Post: 10th February 2009, 18:03
  5. Tool for web application?
    By cool_qt in forum General Programming
    Replies: 3
    Last Post: 9th December 2008, 10:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.