View Full Version : QMessageBox
sonuani
28th March 2008, 12:10
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
jpn
28th March 2008, 12:13
So don't use QMessageBox::information() which sets the informative icon but instantiate a QMessageBox without any icon.
sonuani
28th March 2008, 12:22
I tried like this ...But the MessageBox is appearing for a second and then disappears.Wt to do???
QMessageBox* msg = new QMessageBox(QMessageBox::NoIcon,Title,msg,QMessage Box::Ok,Parent);
msg->show();
jpn
28th March 2008, 12:28
Could you show us the actual code?
sonuani
28th March 2008, 12:32
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.
spud
28th March 2008, 12:40
Use exec() instead of show().
jpn
28th March 2008, 12:41
It should remain visible because you allocate it on the heap, but what if you do:
QMessageBox msg(QMessageBox::NoIcon,Title,msg,QMessageBox::Ok, Parent);
msg.exec();
sonuani
28th March 2008, 12:45
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???
spud
28th March 2008, 13:21
Could it be that the function containing the code gets called twice? Try setting a breakpoint at the line before exec().
yogeshm02
28th March 2008, 16:22
Could it be that the function containing the code gets called twice?
But that should result in two separate messagebox windows.
sonuani
2nd April 2008, 13:11
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.
spud
2nd April 2008, 16:58
Could you show us the relevant code?
sonuani
3rd April 2008, 05:01
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 ...
metalinspired
2nd September 2009, 17:56
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 :D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.