Qt learning path (17): QMessageBox In the Qt standard dialog box

Source: Internet
Author: User

I haven't updated my blog for a long time, mainly because the company is still accepting some items, so I haven't updated it in time. I am also writing a graph program based on Qt, which is basically similar to PS. It mainly uses Qt Graphics View Framework. Now let's continue with the standard Qt dialog box! This time, let's talk about QMessageBox and several similar dialogs. In fact, we have used QMessageBox, just in the previous programs. However, at that time, I made a brief introduction to these dialogs. First, let's take a look at the most familiar QMessageBox: information. We used this in previous Code: 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> QMessageBox: information (NULL," Title "," Content ", QMessageBox: Yes | QMessageBox: No, QMessageBox: Yes ); the following is a simple example: 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" alt = "" src =" http://www.bkjia.com/uploads/allimg/131228/1S4496322-1.png "Border =" 0 "/> now let's look at its function signature from the API: 650) this. width = 650;" onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> static StandardButton QMessageBox: information (QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = OK, StandardButton defaultButton = NoButton ); first, it is static, so we can use the class name to directly access it (it seems like nonsense ...); Then, let's look at the heap of its parameters. The first parameter is parent, indicating its parent component. The second parameter is the title of the dialog box. The third parameter is text, is the content displayed in the dialog box. The fourth parameter, buttons, declares the button placed in the dialog box. By default, only one OK button is placed. This parameter can be used for or operations, for example, if we want to have a Yes button and a No button, we can use QMessageBox: Yes | QMessageBox: No. All the button types can be found in the StandarButton enumeration declared by QMessageBox; the fifth parameter defaultButton is the selected button by default. The default value is NoButton, that is, none of the buttons is selected. So many parameters cannot be remembered! Therefore, when writing with QtCreator, you can enter QMessageBox: information (. Wait a moment, and QtCreator will display the function signature in the upper right corner, A convenient feature! Qt provides five similar interfaces for displaying similar windows. The specific code is not described here, just look at it! 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> QMessageBox: critical (NULL," critical "," Content ", QMessageBox: Yes | QMessageBox: No, QMessageBox: Yes ); 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" alt = "" src =" http://www.bkjia.com/uploads/allimg/131228/1S4491418-4.png "Border =" 0 "/> 650) this. width = 650;" onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> QMessageBox: warning (NULL," warning "," Content ", QMessageBox: Yes | QMessageBox: No, QMessageBox: Yes ); 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" alt = "" src =" http://www.bkjia.com/uploads/allimg/131228/1S4495W7-6.png "Border =" 0 "/> 650) this. width = 650;" onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> QMessageBox: question (NULL," question "," Content ", QMessageBox: Yes | QMessageBox: No, QMessageBox: Yes ); 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" alt = "" src =" http://www.bkjia.com/uploads/allimg/131228/1S4495463-8.png "Border =" 0 "/> 650) this. width = 650;" onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> QMessageBox: about (NULL," About "," About this application "); 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" alt = "" src =" http://www.bkjia.com/uploads/allimg/131228/1S4491U8-10.png "Border =" 0 "/> note that the last about () function does not have the last two buttons about button settings! In the QMessageBox dialog box, HTML tags are supported. Example: 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> QMessageBox: about (NULL," About "," About this <font color = 'red'> application </font> "); the running effect is as follows: 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" alt = "" src =" http://www.bkjia.com/uploads/allimg/131228/1S44942F-12.png "Border =" 0 "/> If You Want To customize an image, it is also very simple. At this time, these static functions cannot be used, but we need to define a QMessagebox to use: 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> QMessageBox message (QMessageBox: NoIcon," Title "," Content with icon .");
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src)" src = "http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif" align = "top"/> message. setIconPixmap (QPixmap ("icon.png "));
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) "src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "align =" top "/> message.exe c (); here we use the exec () function instead of show (), this is a modal dialog box and requires its own event loop. Otherwise, our dialog box will flash through (thanks for the laetitia Reminder ).

In other cases, the relative values defined in the program are relative to the path of the. exe file at runtime. For example, if we write "icon.png", the idea is to find an "icon.png" file in the current directory of .exe. The running effect of this program is as follows: 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" alt = "" src =" http://www.bkjia.com/uploads/allimg/131228/1S4493J9-16.png "Border =" 0 "/> note that we use images in png format. Because Qt's built-in image processing format is png, this will not cause a lot of trouble. If you want to use jpeg images, Qt is supported in the form of plug-ins. There is no problem during development, but if you want to deploy it, pay attention to this. Finally, let's talk about how to deal with dialog box interaction. There are two methods for using the QMessageBox class: static function and constructor. First, let's talk about the static function method. Note that all static functions return a StandardButton, so that we can determine the return value to respond to user operations. 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'onclick =" window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src)" src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "Align =" top "/> QMessageBox: StandardButton rb = QMessageBox: question (NULL," Show Qt "," Do you want to show Qt dialog? ", QMessageBox: Yes | QMessageBox: No, QMessageBox: Yes );
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src)" src = "http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif" align = "top"/> if (rb = QMessageBox: Yes)
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src)" src = "http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif" align = "top"/> {
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src)" src = "http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif" align = "top"/> QMessageBox: aboutQt (NULL, "About Qt ");
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) "src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "align =" top "/>} if you want to use the constructor method, you have to run it yourself: 650) this. width = 650; "onclick = 'window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) "src =" http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif "align =" top "/> QMessageBox message (QMessageBox: NoIcon," Show Qt "," Do you want to show Qt dialog? ", QMessageBox: Yes | QMessageBox: No, NULL );
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src)" src = "http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif" align = "top"/> if(message.exe c () = QMessageBox: Yes)
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src)" src = "http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif" align = "top"/> {
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src)" src = "http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif" align = "top"/> QMessageBox: aboutQt (NULL, "About Qt ");
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'onclick =" window. open ("http://blog.51cto.com/viewpic.php? Refimg = "+ this. src)" src = "http://www.bkjia.com/uploads/allimg/131228/1S44a429-0.gif" align = "top"/>} is actually similar.

This article is from the "bean space" blog, please be sure to keep this source http://devbean.blog.51cto.com/448512/217694

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.