Pyqt mining mine Game Study Notes (4)

Source: Internet
Author: User
Tags qt designer

Another interesting problem is that it reminds you of the importance of reading documents, relevant source code, and testing.

Directly go to the Code, setup. py

"Module: Setup" from LIB import * from config import * form, base = loaduitype ("setup. ui ") Class setupdlg (qdialog, form): def _ init _ (Self): Super (setupdlg, self ). _ init _ () self. setupui (Self) self. SBW. setvalue (Conf. w) self. SBH. setvalue (Conf. h) self. sbmines. setvalue (Conf. mines) def accept (Self): Conf. W = self. SBW. value () Conf. H = self. SBH. value () Conf. mines = self. sbmines. value () Conf. save () Super (Setupdlg, self ). accept () @ pyqtslot () def on_pbsmall_clicked (Self): Self. SBW. setvalue (10) self. SBH. setvalue (10) self. sbmines. setvalue (10) @ pyqtslot () def on_pbmiddle_clicked (Self): Self. SBW. setvalue (16) self. SBH. setvalue (16) self. sbmines. setvalue (40) @ pyqtslot () def on_pbbig_clicked (Self): Self. SBW. setvalue (30) self. SBH. setvalue (16) self. sbmines. setvalue (80) def getsetup (): If setupdlg(.exe C _()! = Qdialog. accepted: return (Conf. W, Conf. h), Conf. Mines

I am confused about the following two problems:

What happened to the function accept? It does not have @ pyqtslot () modifier, unlike the slot function.

Where does qdialog. Accepted come from?

First, ask QT assistant. It says:

Void qdialog: accept () [Virtual slot]

The accept () task is to close the modal dialog box and set the return value accepted.

It also said that the most common method to open a modal dialog box is to call its exec () function. It returns a useful value.

Generally, the default button such as OK is associated with the slot accept (); the button cancel is associated with reject.

Next, let's look at the verification of the relevant code.

First, use QT designer to open setup. UI,

In the buttonbox (default button in the dialog box), OK and cancel are selected.

From the "signal/slot Editor", you can see the signals sent by buttonbox, accepted () and rejected (),

The corresponding slot, accept () and reject ().

Open setup. py in a common text editor and you will see similar text.

Now, it seems that all the problems have been solved. Actually not.

Another important question is: Why accept () calls super (setupdlg, self). Accept ()

Is this call redundant? The best way to understand it is to perform experiments and tests.

Use comments to block super (setupdlg, self). Accept (),

Run main. py and choose config> setup from the program menu. In the displayed dialog box, click OK,

The program does not respond, and the dialog box is not closed.

This proves that you must call qdialog. Accept () to return qdialog. accepted to close the dialog box normally.

Pyqt mining mine Game Study Notes (4)

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.