CN102981861A - Using method of custom control based on Qt - Google Patents
Using method of custom control based on Qt Download PDFInfo
- Publication number
- CN102981861A CN102981861A CN2012105345930A CN201210534593A CN102981861A CN 102981861 A CN102981861 A CN 102981861A CN 2012105345930 A CN2012105345930 A CN 2012105345930A CN 201210534593 A CN201210534593 A CN 201210534593A CN 102981861 A CN102981861 A CN 102981861A
- Authority
- CN
- China
- Prior art keywords
- class
- self
- defined control
- control
- custom control
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Abstract
The invention provides a using method of a custom control based on Qt, which comprises the steps that a class in a basic class library based on the Qt is used as a parent class to derive a custom control class; the custom control class reloads the member function of the parent class or establishes a new constructor to realize self-packaging; the custom control class used as the custom control allocates space for the custom control class and calls the reloaded member function of the parent class or the constructor; and one of the Qt graphical interfaces can include a plurality of independent custom controls for match. The using method of the custom control based on the Qt provided by the invention has the advantages that the coupling degree between software modules can be effectively reduced, and meanwhile, the program code is simplified, thus being easy for maintenance; and in addition, the control can also be operated dynamically.
Description
Technical field
The present invention relates to the graphical interfaces development method of Qt, especially a kind of Qt graphical interfaces development method that is applied in built-in field.
Background technology
In built-in field, take VxWorks as example, under the prerequisite that guarantees system real time, the user-centered interface designing requirement that function is more powerful is more and more higher.At present its embedded WindML shape library assemblies that adopt are developed more under VxWorks, this assembly to the graphical development functions such as window, control a little less than.Qt compares other image development libraries such as WindML, has to support multi-platform, the advantages such as code portability strong, shape library feature richness.The form that adopts VxWorks and Qt to combine can be used as a solution of built-in graphical interface exploitation.
Qt provides abundant class libraries, and is enough for the interface development that adopts the system default style.If directly inherit the basic class libraries of Qt, directly the subclass after inheriting is arranged and quotes simultaneously, although finally can realize the interface requirement, can cause in application program, the derivative a plurality of objects of identical category repeatedly being repeated to arrange.Can reduce like this code readability, increased the degree of coupling of each intermodule, be unfavorable for the maintenance of software.In addition, now widely used visualization toolkit Qt Designer seems at aspects such as control style setting, location layouts and utilizes simultaneously it can not generate control dynamically when program is moved by underaction.
Summary of the invention
The present invention is intended to solve the problems such as the module coupling degree height that exists in the present Qt performance history, the readable difference of code, the invention provides a kind of using method of the self-defined control based on Qt, and it may further comprise the steps:
Derive self-defined control class based on the class in the basic class libraries of Qt as parent, the described self-defined control class described parent member function of heavy duty or newly-built neotectonics function are realized the encapsulation to self;
When self-defined control class uses as self-defined control, for described self-defined control class allocation space and call parent member function or the constructed fuction of described heavy duty.
Preferably, a Qt graphical interfaces comprises a plurality of self-defined control classes, and described a plurality of self-defined control classes are separate and can be used.
Preferably, described encapsulation comprises the encapsulation to pattern, function, event.
Beneficial effect of the present invention:
Use can effectively reduce the degree of coupling between software module based on the self-defined control exploitation of the graphical interfaces of Qt, program code is become succinctly, thereby be easy to safeguard; In addition, can also operate control dynamically.
Description of drawings
By reference to the accompanying drawings, by the detailed description of stating hereinafter, can more clearly understand above-mentioned and other feature and advantage of the present invention, wherein:
Fig. 1 shows process flow diagram of the present invention;
Fig. 2 is for realizing the process flow diagram of the embodiment of the invention 1;
Fig. 3 is for realizing the process flow diagram of the embodiment of the invention 2;
Fig. 4 is for realizing the process flow diagram of the embodiment of the invention 3.
Embodiment
Referring to the accompanying drawing that the embodiment of the invention is shown, hereinafter the present invention will be described in more detail.Yet the present invention can be with many multi-form realizations, and should not be construed as the restriction of the embodiment that is subjected in this proposition.On the contrary, it is abundant and complete open in order to reach proposing these embodiment, and makes those skilled in the art understand scope of the present invention fully.In these accompanying drawings, for clarity sake, may amplify size and the relative size in layer and zone.
As shown in Figure 1, the invention provides a kind of using method of the self-defined control based on Qt, its process is:
Derive self-defined control class based on the class in the basic class libraries of Qt as parent, the described self-defined control class described parent member function of heavy duty or newly-built neotectonics function are realized the encapsulation to self;
When self-defined control class uses as self-defined control, for described self-defined control class allocation space and call parent member function or the constructed fuction of described heavy duty.
Can generate a plurality of self-defined control classes on the Qt graphical interfaces, each self-defined control class is separate, respectively each self-defined control class is independently arranged its pattern, function event etc. in the present embodiment, and each self-defined control class is used in conjunction with each other.
Embodiment 1
Among the embodiment 1 shown in Figure 2, design and used self-defined Label control.Its detailed process is:
The Qlabel class of using Qt to carry derives the label_widget class as self-defined Label control as parent, and its constructed fuction statement is as follows:
Label_widget (QWidget * parent=0, quint16 x=10, quint16 y=10, quint16 w=10, quint16 h=10, QString lbl_text=tr (" "), QString lbl_font=tr (" Song typeface "), quint8 lbl_size=12, bool changeble=false, QColor color_back=Qt::black, QColor color_fore=Qt::white, bool frame=true);
The function that this constructed fuction is finished has: the QLabel class of using Qt to carry arranges Label control background colour, and Label background color and border color change together, for reaching the effect of frame solid, utilize two Label to realize; Bottom Label is used for keeping Graphicxtras Frames Collection, and top layer Label is used for arranging background colour and text color.
Qt requires constructed fuction its parameter when statement of class to force initialize, therefore can come with the most frequently used pattern the parameters initial value, adopts the black matrix wrongly written or mispronounced character as default color herein.Virtual Function setColor (), setText () that in addition can also heavily loaded QLabel class come the color of top layer Label, literal are arranged, in order to dynamically arrange the pattern of label_widget class object in program.Use self-defined label_widget class, only need to call the Label control that a constructed fuction statement just can generate at the screen assigned address the desired style, for example following default calling.
Label_widget* label=new label_widget (NULL, 300,300,200,100, tr (" test of Label control "), tr (" Song typeface "), 9).
Embodiment 2
Among the embodiment 2 shown in Figure 3, design and used self-defined dynamic control.Except the display interface that the position is fixed, sometimes also exist dynamic information to show demand, for example target information in radar PPI display frame.The modes of drawing that adopt were drawn multidate information more in the past, can repaint with XOR, pinup picture, the full frame method such as refresh realizes.Shortcoming is that software programming condition judgment branch is many, processing is loaded down with trivial details and film flicker occurs easily.Utilize Qt, realize dynamic control by self-defined control class, can well show multidate information, not blocked by other windows to affect and need not to redraw, and the problem that method is brought before thoroughly solving.
For realizing the conspicuous mark control of PPI, generate the moving_widget class based on QWidget, for its constructed fuction adds a parametric t ype, be used to specify the target type of drafting.Constructed fuction is defined as follows:
moving_widget::moving_widget(QWidget?*parent,?quint8?type)?:?QWidget(parent)
{
Resize (80,40); // control size
T_type=type; // initialization target type (1: aircraft 2: guided missile 3: helicopter)
}
Heavily loaded member function paintEvent () in the moving_widget class, realize drafting to all types of target icon, lot number, wherein aircraft by the QPainter class:
, guided missile:
, helicopter:
Create target in the aobvious window control of the P that needs display-object, and specifying orientation, distance to show this target icon and lot number, the code of establishment, display-object is as follows:
moving_widget*?target?=?new?moving_widget(this,1);
PPI_Widget::target_draw(target,?a,?r,?6001);
Wherein, target_draw is the privately owned member function of the aobvious window control PPI_Widget of self-defined P, can draw this target in the aobvious relevant position of P according to target azimuth, distance, lot number information.When target component changes, can pass through target-〉direct mobile this moving-target control of move (x, y), and need not to redraw and erase old target at reposition.
Embodiment 3
In embodiment shown in Figure 43, designed and used the self-defined control that contains a plurality of child controls.In the Qt exploitation, the subwindow that often can superpose at main interface needs the subwindow on no title hurdle is realized the mouse drag function sometimes, can not affect again main interface and other subwindows simultaneously.Can realize this subwindow by self-defined control, the member function mouseMoveEvent () of heavily loaded QWidget, mousePressEvent () in self-defined control class, obtain the control displacement by the QMouseEvent event type that returns, by the mobile control of QWidget::move (), just can realize that mouse is to the towing processing of this subwindow again.
If window is comprised of a plurality of child controls, each child control needs that mouse is pressed event and responds.If to the mousePressEvent () of the heavily loaded QWidget of each child control, obviously the code repetition rate is high, has increased simultaneously the degree of coupling of intermodule.At this moment can realize this window by self-defined control, use case filtrator eventFilter () comes the event of child control is unified to process in self-defined control class.
Window is set as example take the aobvious range of radar PPI, it is comprised of a plurality of self-defined label controls, wherein has a lot of label controls all to need to respond the mousebutton event.Utilize self-defined control to generate this window, heavily loaded member function eventFilter () in self-defined control class:
eventFilter(QObject?*?obj,?QEvent?*?event)
{
if(obj?==?label_12)
if(eventtype()?==?QEvent::MouseButtonPress)
label_12->setColor(Qt::white,Qt::black);
}
EventFilter () mainly is comprised of two parameters, at first judge it is which child control needs response events by the obj parameter, determine it is any class event type according to the event parameter again, just can carry out the color setting to the label control that needs respond this event type afterwards.
Use can effectively reduce the degree of coupling between software module based on the self-defined control exploitation of the graphical interfaces of Qt, program code is become succinctly, thereby be easy to safeguard; In addition, can also operate control dynamically.
Because should be understood that the present invention, those skilled in the art can realize not breaking away from the spirit or scope of the present invention with many other concrete forms.Although already described embodiments of the invention, the present invention should be understood and these embodiment should be restricted to, make within the spirit and scope of the invention that those skilled in the art can define such as appended claims and change and revise.
Claims (3)
1. the using method based on the self-defined control of Qt is characterized in that, comprises following process:
Derive self-defined control class based on the class in the basic class libraries of Qt as parent, the described self-defined control class described parent member function of heavy duty or newly-built constructed fuction are realized the encapsulation to self;
When self-defined control class uses as self-defined control, for described self-defined control class allocation space and call parent member function or the constructed fuction of described heavy duty.
2. the using method of the self-defined control based on Qt as claimed in claim 1 is characterized in that a Qt graphical interfaces comprises a plurality of self-defined control classes, and described a plurality of self-defined control classes are separate and be used.
3. the using method of the self-defined control based on Qt as claimed in claim 1 is characterized in that described encapsulation comprises the encapsulation to a kind of or its combination in pattern, function, the event.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2012105345930A CN102981861A (en) | 2012-12-12 | 2012-12-12 | Using method of custom control based on Qt |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2012105345930A CN102981861A (en) | 2012-12-12 | 2012-12-12 | Using method of custom control based on Qt |
Publications (1)
Publication Number | Publication Date |
---|---|
CN102981861A true CN102981861A (en) | 2013-03-20 |
Family
ID=47855925
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2012105345930A Pending CN102981861A (en) | 2012-12-12 | 2012-12-12 | Using method of custom control based on Qt |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102981861A (en) |
Cited By (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103544005A (en) * | 2013-09-10 | 2014-01-29 | Tcl集团股份有限公司 | Expansion developing method and device for Android custom control |
CN103544018A (en) * | 2013-10-31 | 2014-01-29 | 成都飞鱼星科技开发有限公司 | Rapid processing method for large-scale module self-drawing under wxWidgets frame |
CN105607985A (en) * | 2015-09-29 | 2016-05-25 | 中国船舶重工集团公司第七0九研究所 | Qt graphical interface software-based operation log recording method and system |
CN106815018A (en) * | 2016-12-27 | 2017-06-09 | 国电南瑞科技股份有限公司 | Tramcar comprehensive operation dispatches the integral design method of system man-machine interface |
CN107291340A (en) * | 2017-06-12 | 2017-10-24 | 北京小鸟看看科技有限公司 | Realize method, computing device and the storage medium of interfacial effect |
CN107678744A (en) * | 2017-09-12 | 2018-02-09 | 平安科技(深圳)有限公司 | Application controls pattern customizing method, device and computer-readable recording medium |
CN107977203A (en) * | 2017-10-20 | 2018-05-01 | 捷开通讯(深圳)有限公司 | The creation method of storage device, application program control and user interface |
CN108228287A (en) * | 2016-12-15 | 2018-06-29 | 龙芯中科技术有限公司 | The generation method and device of user interface controls based on QT |
CN109377424A (en) * | 2018-08-23 | 2019-02-22 | 深圳点猫科技有限公司 | A kind of self-defined control implementation method and electronic equipment based on education operating system |
CN109508188A (en) * | 2018-10-12 | 2019-03-22 | 上海金大师网络科技有限公司 | GUI Dynamic Distribution method, system and medium |
CN111309325A (en) * | 2020-01-22 | 2020-06-19 | 上海钧正网络科技有限公司 | Method and device for reference of third-party library and mobile terminal |
CN111324348A (en) * | 2018-12-17 | 2020-06-23 | 北京华航无线电测量研究所 | Man-machine interaction interface implementation method of ground control platform of guide equipment |
CN113064585A (en) * | 2021-04-30 | 2021-07-02 | 中国电子科技集团公司第二十九研究所 | JSON mode-based real-time message interface automatic generation method |
CN114217894A (en) * | 2021-12-10 | 2022-03-22 | 中国人民解放军96901部队25分队 | Method for realizing radar screen display by adopting Qt |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1547365A (en) * | 2003-12-10 | 2004-11-17 | 珠海金山软件股份有限公司 | Method for implementing free switching between homepage controls |
US20070233454A1 (en) * | 2006-03-29 | 2007-10-04 | Fujitsu Limited | Web load test method and web load test program |
CN102262539A (en) * | 2011-07-29 | 2011-11-30 | 深圳市科陆电子科技股份有限公司 | Implementation method for self-defined paging dataTable control based on struts2 technology |
-
2012
- 2012-12-12 CN CN2012105345930A patent/CN102981861A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1547365A (en) * | 2003-12-10 | 2004-11-17 | 珠海金山软件股份有限公司 | Method for implementing free switching between homepage controls |
US20070233454A1 (en) * | 2006-03-29 | 2007-10-04 | Fujitsu Limited | Web load test method and web load test program |
CN102262539A (en) * | 2011-07-29 | 2011-11-30 | 深圳市科陆电子科技股份有限公司 | Implementation method for self-defined paging dataTable control based on struts2 technology |
Non-Patent Citations (1)
Title |
---|
ABLAB: "QT用户自定义控件", 《新浪博客》 * |
Cited By (24)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103544005B (en) * | 2013-09-10 | 2017-08-08 | Tcl集团股份有限公司 | A kind of regarded as output controlling method and device of Android self-defined controls |
CN103544005A (en) * | 2013-09-10 | 2014-01-29 | Tcl集团股份有限公司 | Expansion developing method and device for Android custom control |
CN103544018A (en) * | 2013-10-31 | 2014-01-29 | 成都飞鱼星科技开发有限公司 | Rapid processing method for large-scale module self-drawing under wxWidgets frame |
CN103544018B (en) * | 2013-10-31 | 2016-09-28 | 成都飞鱼星科技股份有限公司 | Under wxWidgets framework, extensive assembly is from the immediate processing method drawn |
CN105607985A (en) * | 2015-09-29 | 2016-05-25 | 中国船舶重工集团公司第七0九研究所 | Qt graphical interface software-based operation log recording method and system |
CN105607985B (en) * | 2015-09-29 | 2018-02-06 | 中国船舶重工集团公司第七0九研究所 | Operation log recording method and system based on Qt graphic interface softwares |
CN108228287A (en) * | 2016-12-15 | 2018-06-29 | 龙芯中科技术有限公司 | The generation method and device of user interface controls based on QT |
CN106815018A (en) * | 2016-12-27 | 2017-06-09 | 国电南瑞科技股份有限公司 | Tramcar comprehensive operation dispatches the integral design method of system man-machine interface |
CN107291340A (en) * | 2017-06-12 | 2017-10-24 | 北京小鸟看看科技有限公司 | Realize method, computing device and the storage medium of interfacial effect |
CN107291340B (en) * | 2017-06-12 | 2020-10-09 | 北京小鸟看看科技有限公司 | Method for realizing interface effect, computing equipment and storage medium |
WO2019052115A1 (en) * | 2017-09-12 | 2019-03-21 | 平安科技(深圳)有限公司 | Application control style customization method and apparatus, and computer-readable storage medium |
CN107678744A (en) * | 2017-09-12 | 2018-02-09 | 平安科技(深圳)有限公司 | Application controls pattern customizing method, device and computer-readable recording medium |
WO2019076307A1 (en) * | 2017-10-20 | 2019-04-25 | 捷开通讯(深圳)有限公司 | Storage apparatus, application control creation method, and user interface creation method |
CN107977203A (en) * | 2017-10-20 | 2018-05-01 | 捷开通讯(深圳)有限公司 | The creation method of storage device, application program control and user interface |
CN109377424A (en) * | 2018-08-23 | 2019-02-22 | 深圳点猫科技有限公司 | A kind of self-defined control implementation method and electronic equipment based on education operating system |
CN109508188A (en) * | 2018-10-12 | 2019-03-22 | 上海金大师网络科技有限公司 | GUI Dynamic Distribution method, system and medium |
CN109508188B (en) * | 2018-10-12 | 2022-09-06 | 上海金大师网络科技有限公司 | GUI dynamic layout method, system and medium |
CN111324348A (en) * | 2018-12-17 | 2020-06-23 | 北京华航无线电测量研究所 | Man-machine interaction interface implementation method of ground control platform of guide equipment |
CN111309325A (en) * | 2020-01-22 | 2020-06-19 | 上海钧正网络科技有限公司 | Method and device for reference of third-party library and mobile terminal |
CN111309325B (en) * | 2020-01-22 | 2023-08-18 | 上海钧正网络科技有限公司 | Third party library reference method and device and mobile terminal |
CN113064585A (en) * | 2021-04-30 | 2021-07-02 | 中国电子科技集团公司第二十九研究所 | JSON mode-based real-time message interface automatic generation method |
CN113064585B (en) * | 2021-04-30 | 2023-04-11 | 中国电子科技集团公司第二十九研究所 | JSON mode-based real-time message interface automatic generation method |
CN114217894A (en) * | 2021-12-10 | 2022-03-22 | 中国人民解放军96901部队25分队 | Method for realizing radar screen display by adopting Qt |
CN114217894B (en) * | 2021-12-10 | 2023-09-05 | 中国人民解放军96901部队25分队 | Method for realizing radar screen display by adopting Qt |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102981861A (en) | Using method of custom control based on Qt | |
CN104063211B (en) | Layout system for devices with variable display screen size and orientation | |
CN105630939B (en) | A kind of general painting canvas input interface design method and device | |
US10073580B2 (en) | Apparatus and method for positioning windows on a display | |
US5555368A (en) | Object-oriented multi-tasking view framework | |
CA2027157C (en) | Computer user interface | |
US5621434A (en) | Cursor manipulation system and method | |
US6335743B1 (en) | Method and system for providing a resize layout allowing flexible placement and sizing of controls | |
CN112269604A (en) | Window interaction method and device for compatibly running Android application on Linux | |
CA2178585C (en) | Object-oriented task security framework | |
US20030067497A1 (en) | Method and device for modifying a pre-existing graphical user interface | |
EP0788646A1 (en) | Object-oriented system for servicing windows | |
US5615326A (en) | Object-oriented viewing framework having view grouping | |
CN101216762A (en) | Interface library architecture | |
CN112363794A (en) | Rendering method of front-end list type component and electronic equipment | |
CN112099789A (en) | Human-computer interaction design method, device, equipment and storage medium | |
US20170352174A1 (en) | Method and system for visual data management | |
CN112445564B (en) | Interface display method, electronic device and computer readable storage medium | |
WO2017113551A1 (en) | System and method for operating system of mobile device | |
CN101876917A (en) | Control development method and device | |
US5524200A (en) | Object-oriented non-rectilinear viewing framework | |
CN103955469A (en) | Method and device for page scaling in browser | |
CN102081521B (en) | A kind of general development platform of military hardware operation interface | |
CN111724462A (en) | Three-dimensional rendering method in Chrome browser | |
CN102004610A (en) | User interface, system and method for executing or ending programs by towing |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C12 | Rejection of a patent application after its publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20130320 |