QT project leader must master Ui designer features --Promote to!

Original link as follows:

http://blog.chinaunix.net/uid-25223983-id-90838.html


As a QT person in charge of the project, you always have to often face the situation:

    Your team has received a task, and then you put this task broken down into specific modules, then your team members have successfully completed the task you arrangement. They doWell, module, and then presented to you. Now it's your turn to their modules are combined into a program of ......

This network of networks is difficult because:

     1,   the module does everyone have their own interface, you have to design and define what a good time in the overall program, in what position, who modules will take effect?

     2,   different people have different module functions and operations, how you arrange the button corresponding to this operation, the buttons and the event, when it was activated?

     3,   how to make their modules and the main program the perfect fusion of a button will not cause the entire layout of the hidden confusion?

     4,   the project file is confusing it? Is not tell where who did it?

      All the answers, in QT designer, the use of QT designer Promte to function with QT strong signal and plug nest feature that allows you easy and free classes evolved into the way you want, of course, can evolve into you the crew module presented to you ......

We have a specific project to explain:

       A student is responsible for producing a display module, this module is a calendar (casually given, for convenience only demo)
       B student is responsible for making a statistics module, the module has a counter and a digital input box ( QSpinBox )

   You come to these two parts together and try to make beautiful interface does not affect the layout of the base.

   The first is A classmate of the module, we will soon be able to do:

   We can see the generated project is Student_A named after the corresponding class name, the header file (.h) , the source file (.cpp) and form (.ui) files are based on stua_widget named. Indicates that this class inherits word Qwidget , the studentA responsible for the development.

      Then control is entrusted, and also very simple ......

      We can add a layout ( QLayout ), in order to adapt to stretch or compress.

       Then successful, compile, submit it to your head of it.

    Similarly you can make StudentB modules:

    Like just now, not repeat them here ......

    Well, it looks like this:  

     Then the main project, the person in charge of CG creation:

      First, build the project:

      Then the interface, you can use a QstackWidget to avoid the different modules and the corresponding button interfere with each other, one would say ...... also, like this:

      One might ask: ah? You put things yet? Why do I see anything? Oh, if you look at enough of your own, you would have found the upper right corner to the left and right of aArrow: In fact, I not only put a QstackWidget , I also for the Widget to make a layout. I do not believe you can see:


image

      This StackWidget there are two, each page has its own Qwidget , this is very scientific. Because all QT GUI classes, including the form member and QmainWindow are directly or indirectly inherits from Qwidget ! And we have to do today is to make these two Qwidget evolution, evolution is StudentA and StudentB module production - that is the focus of this post:

First, we need to StudentA and StudentB results of the work are added to the project to:

      Open this file in the folder where the project will StudentA and StudentB project (even copy the folder come together):


      Then add the required files in the project file,  in addition to main.cpp outside without adding (because a project can only have one main ) rest depends on your needs, if you need to be able to edit the main project StudentA and StudentB modules can Ui also add in

(At that time CG project will regenerate in the process of compiling the ui_StudentA.h and   ui_StudentB.h, this is something, not the table ......), then becomes this:

     We can see which file, who wrote a glance in our project, and can also be edited, because the file exists in the project file, so Gcc will change again according to our compile time to compile the files.

     Well, finally today the most interesting place, ready to enjoy the fun of that?

Let it evolve our class! ! !

The first step, select pageone this Qwidget , the right mouse button, the Promote to :

 

The second step, fill in the information:

Base class chose Qwidget

Promote to class to enter StudentA and StudentB in their header files ( .h classes defined) file (do not knock on the wrong Oh!):

      Finally, the position of the header file: of course Student_A folder stua_widget.h ah, because the file was there by myself thing (like nonsense ......):

Anyway, so, the first point Add button, a class may evolve on the well, check it dot promote on the line:

      Haha, it's that simple, you look at the original Qwidget of page What becomes:

      And a compilation you will miraculously find StudentA do obediently lying on your calendar already QstackWidget the page where friends:

      The same can be QstackWidget join the B students module, and you can directly in the main projects A , B two students module be modified. You make changes will be Gcc compiler to recompile. (This is mainly inserted you can write some nests in their class, and then in your class that is cg_widget initialization time to bind these nests, so that you can to the A , B two classes send messages between the completion of the class communication, ha ha ......

      Finally, he added that the point QstackWidget page switching it:

Use this code can be to change the current page in the program:

      You can do a button on the main panel, switched paging signal by binding to and interposed nest tab. Of course, the nest should have inserted the code, it is naturally the sentence, hey, well, today said that it, take advantage of this feature, put together our efforts to develop more efficient, the project leader You should master their own good experience of it ......

Published 42 original articles · won praise 148 · views 410 000 +

Guess you like

Origin blog.csdn.net/baidu_37503452/article/details/104529917