Results 1 to 20 of 41

Thread: How QMessageBox can be inherited.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default How QMessageBox can be inherited.

    i have displayed a message by using QMessageBox and i have done all the translation related to my message but the Yes / No option cannot be translated. So how can it be done.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How QMessageBox can be inherited.

    you can get access to dialog buttons using this method
    http://doc.trolltech.com/4.4/qmessagebox.html#button

    so, in you case you need to do
    Qt Code:
    1. ...
    2. msgBox.button(QMessageBox::Yes)->setText(tr(....));
    3. ...
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2008
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How QMessageBox can be inherited.

    i have added a message in message box box , but how the Ok can be changed

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How QMessageBox can be inherited.

    this code didn't help?
    Qt Code:
    1. ...
    2. msgBox.button(QMessageBox::Ok)->setText(tr(....));
    3. ...
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jul 2008
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How QMessageBox can be inherited.

    yeah it wont work.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How QMessageBox can be inherited.

    this code works fine
    Qt Code:
    1. QMessageBox msg(QMessageBox::Information, tr("information"), tr("Some inportant information"),
    2. QMessageBox::Ok | QMessageBox::Yes | QMessageBox::Save | QMessageBox::Discard);
    3. msg.button(QMessageBox::Ok)->setText(tr("My Ok label"));
    4. msg.button(QMessageBox::Yes)->setText(tr("My Yes label"));
    5. msg.button(QMessageBox::Save)->setText(tr("My Save label"));
    6. msg.button(QMessageBox::Discard)->setText(tr("My Discard label"));
    7. msg.exec();
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jul 2008
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How QMessageBox can be inherited.

    i did it but it said tr identifier not found.

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How QMessageBox can be inherited.

    use QObject::tr(...)

  9. #9
    Join Date
    Jul 2008
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How QMessageBox can be inherited.

    how i can use it with set text.

    and also it shows "use of undefined type Qabstract button" with button means msgBox.button

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How QMessageBox can be inherited.

    Quote Originally Posted by rajveer View Post
    how i can use it with set text.
    see http://doc.trolltech.com/4.4/qobject.html#tr

    Quote Originally Posted by rajveer View Post
    and also it shows "use of undefined type Qabstract button" with button means msgBox.button
    include
    Qt Code:
    1. #include <QAbstractButton>
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jul 2008
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How QMessageBox can be inherited.

    msg.button(QMessageBox::Ok)->setText(tr("My Ok label"));

    here it shows tr identifier not found.
    so here how can i use QObject.

  12. #12
    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 QMessageBox can be inherited.

    Quote Originally Posted by rajveer View Post
    i have displayed a message by using QMessageBox and i have done all the translation related to my message but the Yes / No option cannot be translated. So how can it be done.
    It's enough to provide translations for the proper context and message. Look into the source code of QMessageBox to see what it expects. There is really no need to making things more complex than they really are.

  13. #13
    Join Date
    Jul 2008
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How QMessageBox can be inherited.

    Its not working , how the QMessageBOx button can be translated.

  14. #14
    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 QMessageBox can be inherited.

    What is not working? What exactly did you do?

  15. #15
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How QMessageBox can be inherited.

    use QObejct::tr and Qt Linguist for translation.

  16. #16
    Join Date
    Jul 2008
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How QMessageBox can be inherited.

    i have to change all the buttons which are coming when we are using QMessageBox in the application . the text message is changed by using tr but the OK , yes, No buttons can not be changed. so how can i do this?

    my mentor said u hav to create a class and derive it from QMessageBox and then remove that buttons and add ur own buttons. but how can i do that. means i have using it in one way which the other sir told me in the forum.

  17. #17
    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 QMessageBox can be inherited.

    You don't have to do anything like that. Read my post again, it says exactly what you need to do and believe me it will work as Qt does it exactly the same when it translates the message box with a proper translator installed.

Similar Threads

  1. QMessageBox buttons appearance
    By yartov in forum Qt Programming
    Replies: 6
    Last Post: 26th June 2008, 01:36
  2. Display row Number in QMessageBox
    By arunvv in forum Newbie
    Replies: 6
    Last Post: 1st May 2008, 23:24
  3. Re: Help on QMessageBox
    By arunvv in forum Newbie
    Replies: 2
    Last Post: 25th March 2008, 23:45
  4. Qt4: Sorting QAbstractItemVew inherited view
    By nando in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2008, 18:30
  5. QMessageBox problem in Qtopia
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 8th February 2008, 09:22

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.