Page 1 of 3 123 LastLast
Results 1 to 20 of 41

Thread: How QMessageBox can be inherited.

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


    Qt Code:
    1. ...
    2. msg.button(QMessageBox::Ok)->setText(QObject::tr("My Ok label"));
    3. ...
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: How QMessageBox can be inherited.

    I m doing like this:

    Qt Code:
    1. void MyMessageBox: QMessageBox(QWidget* parent, const QString& title, const QString& text, const QMessageBox&)
    2. {
    3. box.removeButton("OK");
    4. box.addButton("OK");
    5. box.exec();
    6. return;
    To copy to clipboard, switch view to plain text mode 

    it is not working.

    please help me out.
    Last edited by jpn; 8th September 2008 at 16:31. Reason: missing [code] tags

  14. #14
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How QMessageBox can be inherited.

    MyMessageBox: QMessageBox

    I guess u are inheriting from QMessageBox,,,
    then why are u making another instance of QMessageBox inside the ctor ??

  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.

    Quote Originally Posted by rajveer View Post
    I m doing like this:

    void MyMessageBox: QMessageBox(QWidget* parent, const QString& title, const QString& text, const QMessageBox&)
    {
    QMessageBox box;
    box.removeButton("OK");
    box.addButton("OK");
    box.exec();
    return;

    it is not working.

    please help me out.
    I don't understand what do you want to do.

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

    Default Re: How QMessageBox can be inherited.

    my mentor said u have to create ur own class and derive it from QMessageBox. After dat then u have to remove the already added button and add ur own buttons.

  17. #17
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How QMessageBox can be inherited.

    What do you want to do anyway...
    in the first post ur prob was regaarding translation. Now its something else.
    If you can tell what u want to achieve, may be we can tell a way..

  18. #18
    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.

    I asked about your code. nevermind.
    example
    Qt Code:
    1. ----h----
    2. #ifndef TEST_H
    3. #define TEST_H
    4.  
    5. #include <QMessageBox>
    6.  
    7. class Test: public QMessageBox
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. Test(QMessageBox::Icon icon, const QString &title,
    13. const QString &text,
    14. QMessageBox::StandardButtons buttons = NoButton,
    15. QWidget *parent = 0,
    16. Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
    17. ~Test();
    18. };
    19.  
    20. #endif
    21. ---cpp---
    22. #include "test.h"
    23.  
    24. Test::Test(Icon icon, const QString &title,
    25. const QString &text, StandardButtons buttons,
    26. QWidget *parent, Qt::WindowFlags f)
    27. :QMessageBox(icon, title, text, buttons, parent, f)
    28. {
    29. QAbstractButton *ok = button(Ok);
    30. removeButton(ok);
    31. addButton(tr("MyButton"), AcceptRole);
    32. }
    33.  
    34. Test::~Test()
    35. {
    36. }
    37.  
    38. ---another_cpp_code---
    39. ....
    40. Test test(QMessageBox::Information, QObject::tr("information"),
    41. QObject::tr("Some important information"), QMessageBox::Ok | QMessageBox::No);
    42. test.exec();
    43. ....
    To copy to clipboard, switch view to plain text mode 
    I don't see any trouble. is it hard to you?

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

    Default Re: How QMessageBox can be inherited.

    an error is coming:

    'void QMessageBox::addButton(QAbstractButton *,QMessageBox::ButtonRole)' : cannot convert parameter 1 from 'QString' to 'QAbstractButton *'

  20. #20
    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.


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.