QT Popup A dialog box

Source: Internet
Author: User

Create a new file:

Press the key to go to the slot and add the slot function:

void mainwindow::on_pushbutton_clicked ()
{
    Com_config * c = new com_config ();

    C->show ();    c->exec ();
}

Ps:
defined as Com_config c = new Com_config (), the interface will flash back. is defined as a pointer type and does not flash back.

Pop-up interface:

Add "OK" and "Cancel" buttons:

button to go to the slot to add code:

void com_config::on_pushbutton_ok_clicked ()
{
    com_config::accept ();
}
void com_config::on_button_reject_clicked ()
{
    com_config::reject ();
}

Ps:
1. Close the main window and exit the program is Qapplication::exit ()
2. If it is Qdialog, accept () or reject ()
3. For all Qwidget:close ()

Pps:
Show () differs from EXEC ():
Show ():
Displays a non-modal dialog box. Control is immediately returned to the calling function.
The popup window is a modal dialog box, depending on the value of the modal property.

EXEC ():
Displays a modal dialog box and locks the program until the user closes the dialog box. The function returns a dialogcode result.
During a dialog pop-up, the user cannot switch to another window under the same program until the dialog box is closed.

Let me start with a little bit of understanding of the modal and modeless dialogs:
Modal dialog box, the entire program is locked and waiting until the dialog box is closed when the popup window is displayed. The return value of the dialog box is often required to do the following. Such as: Confirmation window (select Yes or no).
Non-modal dialog box, after calling the pop-up, the call returns immediately, continuing with the following operation. Here is just a call to the command to emit, do not wait nor do any processing. such as: Find box.

If you want to fix the size of the dialog box, you can use two methods:

One way is to set its maximum size and minimum size, and make their values equal, equal to the size of the window you are currently setting.
A simple example:

Setminimumsize (370, 150); 

Other such as height and width can generally be ignored.

Another way is to use setfixedsize (), so that a sentence can solve the problem.
A simple example:

A practical example:

As a result of this setting, even the maximum Minimum button of the dialog box is
 this->setfixedsize (This->width (), This->height ());

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.