Dynamic dialog box under QT

Source: Internet
Author: User

In a recently written program, some places have to interact with the user, require the user to enter a few parameters, then the program continues to go down. 2 questions were encountered. One is how to write a custom dialog box, and the other one is how to get stuck.

Let's say how to customize the dialog box. In fact, the same ideas in VC. Write their own dialog box class, inherit from Qdialog, as to how the form painting also divided into 2 kinds of ideas, one is the UI in the picture, with Qt own uiloader, such as need to import the dialog box, but also a code of their own painting. I'm very much in favor of the second approach, better control, better handling of parameter delivery. Don't say a word, just stick to the dialog box you wrote.


Class Setposdialog:p ublic qdialog
Setposdialog (Qwidget *parent=0);
Qlabel *x_label,*y_label,*z_label;
Qlineedit *x_lineedit,*y_lineedit,*z_lineedit;
Qpushbutton *submitbutton,*cancelbutton;


Point3D m_3d;
float m_x,m_y,m_z;

Private Slots:
void submitclicked ();
void cancelclicked ();

Code Explanation: is the slot for 2 buttons, as well as some control pointers, and a Point3D that accepts parameters. Implementation of the code is not affixed, it is really simple. The key is still the following if the dialog box is stuck.

2, regarding this question, I think the VC processing is very good, has divided the modal dialog box and the Non-modal dialog box. (maybe there's a qt, but I didn't touch it, I haven't met it yet.)

The first call to the dialog box is as follows:
Setposdialog *h=new Setposdialog ();
H->show ();
if (h->exec () ==qdialog::accepted| | H->exec () ==qdialog::rejected)
The meaning of this is, whether the above dialog box is the point of the determination, or cancel, all do the following, but no point, it is not executed ~

In this case, however, you have to write qdialog::accepted or qdialog::rejected in the corresponding slots of the buttons in your own dialog implementation class.

Okay ~ the notes are finished. I find myself more and more unlikely to express myself, but fortunately, I can still read these messy things. ~

Beyond C + + original articles, reproduced please indicate the source and keep the original link

This article link: http://www.beyondc.cn/qt-with-dynamic-dialog-box.html

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.