Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement drag Control with Qt

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Qt how to achieve drag control, the article introduces in great detail, has a certain reference value, interested friends must read!

I. Preface

The last article loaded the plug-in and displayed all the controls in the plug-in in the list box. This time, the user selects a control to drag onto the canvas, releases it, and automatically instantiates the control at the release position. This requires the use of dropEvent and dragEnterEvent events to re-implement these two events, filter the dragged object and call a function to instantiate the control. Instantiate the control while instantiating the control to follow the control to stretch to resize and position. It should be noted that dragEnterEvent is a must, many people think that dragging as long as the realization of dropEvent can not, in fact, no effect, need to first dragEnterEvent to filter the implementation of event- > accept () to do, otherwise there is no effect at all, many people, especially beginners are hanging here, I just fell here, good pain!

Second, the functions realized

Automatically load all the controls in the plug-in file to generate a list, with more than 120 controls by default.

Drag to the canvas to automatically generate the corresponding control, WYSIWYG.

On the right side of the Chinese attribute bar, change the corresponding attributes immediately applied to the corresponding selected controls, intuitive and concise, very suitable for rookies to use.

The original attribute bar text translation mapping mechanism is extremely efficient, and it is very convenient to expand the attribute bar of other languages.

The properties of all controls are automatically extracted and displayed in the right property bar, including the enumerated value drop-down box.

Support manual selection of plug-in files, external import plug-in files.

You can export all control configuration information for the current canvas to a xml file.

You can manually select the xml file to open the control layout and automatically load the control according to the xml file.

Can pull the slider, check the analog data check box, text box input, three ways to generate data to apply all controls.

The control supports eight azimuth pull adjustments, adapts to any resolution, and fine-adjusts the position up and down the keyboard.

Through the serial port acquisition, network acquisition, database collection of three ways to set data.

The code is extremely concise, the comments are very detailed, and can be used as an embryonic form of configuration to expand more functions.

Pure Qt writing, support any Qt version + any compiler + any system.

Third, effect picture

4. Core code void frmMain::dropEvent (QDropEvent * event) {int row = listNames.indexOf (pressedItem); if (row)

< 0) { return; } //根据最后按下的控件位置生成控件 QPoint point = event->

Pos (); point.setX (point.x ()-ui- > centralwidget- > x ()); newWidget (row, point);} void frmMain::dragEnterEvent (QDragEnterEvent * event) {if (event- > mimeData ()-> hasFormat ("application/x-qabstractitemmodeldatalist")) {event- > setDropAction (Qt::MoveAction); event- > accept ();} else {event- > ignore () }} void frmMain::newSelect (QWidget * widget) {/ / instantiated SelectWidget * select = new SelectWidget (ui- > centralwidget); connect (select, SIGNAL (widgetPressed (QWidget *)), this, SLOT (widgetPressed (QWidget *)); connect (select, SIGNAL (widgetRelease (QWidget *)), this, SLOT (widgetRelease (QWidget *)); connect (select, SIGNAL (widgetDelete (QWidget *)), this, SLOT (widgetDelete (QWidget *) Select- > setWidget (widget); selectWidgets.append (select);} void frmMain::newWidget (int row, const QPoint & point) {/ / the list is generated according to the same index, so here we directly index the row QWidget * widget = listWidgets.at (row)-> createWidget (ui- > centralwidget); widget- > move (point); widget- > resize (widget- > sizeHint ()); / / instantiate the form with the control newSelect (widget) / / immediately execute to get the focus and set the property widgetPressed (widget);} this is all the content of the article "how to implement drag and drop controls in Qt". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report