Results 1 to 14 of 14

Thread: QMessageBox

  1. #1
    Join Date
    Feb 2008
    Posts
    47
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post QMessageBox

    hi,
    I want a messagebox with no icon and with ok button alone.
    I wrote my code like this.
    QMessageBox::information(Parent,Title,msg,QMessage Box::Ok);
    It displays a information icon.
    I dont want it.How to remove that.
    THANKS

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMessageBox

    So don't use QMessageBox::information() which sets the informative icon but instantiate a QMessageBox without any icon.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    47
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: QMessageBox

    I tried like this ...But the MessageBox is appearing for a second and then disappears.Wt to do???

    Qt Code:
    1. QMessageBox* msg = new QMessageBox(QMessageBox::NoIcon,Title,msg,QMessageBox::Ok,Parent);
    2. msg->show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 28th March 2008 at 12:26. Reason: missing [code] tags

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMessageBox

    Could you show us the actual code?
    J-P Nurmi

  5. #5
    Join Date
    Feb 2008
    Posts
    47
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: QMessageBox

    I m trying to convert the below vc++ code to Qt.

    ::MessageBox(Parent->m_hWnd, msg, title, MB_OK);

    And i have sent u the actual code i had replaced previously.

  6. #6
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMessageBox

    Use exec() instead of show().

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

    sonuani (28th March 2008)

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMessageBox

    It should remain visible because you allocate it on the heap, but what if you do:
    Qt Code:
    1. QMessageBox msg(QMessageBox::NoIcon,Title,msg,QMessageBox::Ok,Parent);
    2. msg.exec();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  9. #8
    Join Date
    Feb 2008
    Posts
    47
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: QMessageBox

    Now the messagebox is appearing properly.If i click on the ok button then the messagebox should close.
    At present the messagebox is getting closed only after I click on ok button 2 times.Why is that so???

  10. #9
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMessageBox

    Could it be that the function containing the code gets called twice? Try setting a breakpoint at the line before exec().

  11. #10
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMessageBox

    Quote Originally Posted by spud View Post
    Could it be that the function containing the code gets called twice?
    But that should result in two separate messagebox windows.

  12. #11
    Join Date
    Feb 2008
    Posts
    47
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: QMessageBox

    hi,
    when i debug the control passes through the messagebox only once.But when i execute it it gets displayed 2 times (i.e If i give ok to the first messagebox then another one appears)
    What is the problem with my code?
    Thanks.

  13. #12
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMessageBox

    Could you show us the relevant code?

  14. #13
    Join Date
    Feb 2008
    Posts
    47
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: QMessageBox

    Actually when i press enter to close the messagebox.Eventfilter in my class is getting called again and messagebox is getting displayed again.
    How to differenciate between the enter that i pressed to close the messagebox and the ordinary enter that i press ...

  15. #14
    Join Date
    Aug 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb Re: QMessageBox

    This is rather old post but here’s why this is happening in case someone else has a same problem. When you press a key on keyboard (and release it, thus actually making one “click” of that key) there are two events emitted. QEvent::KeyPress and then QEvent::KeyRelease. The first one closes the message box and object that gets the focus (after closing message box) also gets QEvent::KeyRelease called for it, which causes that object to “think” that key was pressed inside it. Filter out QEvent::KeyRelease event for object that can get focus after message box closes. Worked for me

Similar Threads

  1. Re: Help on QMessageBox
    By arunvv in forum Newbie
    Replies: 2
    Last Post: 25th March 2008, 23:45
  2. QMessageBox problem in Qtopia
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 8th February 2008, 09:22
  3. QMessageBox - no dialog title on Mac OS?
    By will49 in forum Qt Programming
    Replies: 1
    Last Post: 8th October 2007, 14:07
  4. customize the Icon QMessageBox
    By QiT in forum Newbie
    Replies: 1
    Last Post: 26th August 2006, 10:40
  5. Change icons on static QMessageBox
    By manucorrales in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2006, 19:00

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.