[GO] 360安全卫士一 -- 移动的窗体

源码地址: https://github.com/JianBiHua/go_360_safe

  1. 这个代码实现的功能就是现实一个920*580的可通过鼠标左键移动的窗体.
  2. 注释还算详细,就不单独讲解了.

代码如下:

	import (
		"fmt"
		"github.com/therecipe/qt/core"
		"github.com/therecipe/qt/gui"
		"github.com/therecipe/qt/widgets"
		"io/ioutil"
		"os"
	)

	func main() {
		// 起始点击坐标
		var startPos *core.QPoint
		
		//
		app = widgets.NewQApplication(len(os.Args), os.Args)
		
		window := widgets.NewQMainWindow(nil, 0)
		// 设置标题
		window.SetWindowTitle("360手机助手")
		// 设置宽高
		window.SetMinimumSize2(920, 580)
		// 无法缩放
		window.SetMaximumHeight(580)
		window.SetMaximumWidth(920)
		// 设置背景色
		window.SetStyleSheet("background-color: #F5F5F5")
		// 去掉标题栏
		window.SetWindowFlags(core.Qt__FramelessWindowHint)
		// 启动鼠标移动
		window.SetMouseTracking(true)
		// 鼠标移动
		window.ConnectMouseMoveEvent(func(event *gui.QMouseEvent) {
			// 鼠标左键按下时处理
			if event.Button() == core.Qt__LeftButton {
				window.Move2(windowPos.X()+event.GlobalX()-startPos.X(),
					windowPos.Y()+event.GlobalY()-startPos.Y())
			}
		})
		// 鼠标按下
		window.ConnectMousePressEvent(func(event *gui.QMouseEvent) {
			// 左键按下时处理
			if event.Button() == core.Qt__LeftButton {
				// 保存坐标
				startPos = event.GlobalPos()
				windowPos = window.Pos()
			}
		})
	
		window.Show()
		app.Exec()
	}

使用这个QT的库,写UI感觉就是在用QT写一样,挺方便;有些不会的qt知识直接百度,然后在这使用。方便!!!

猜你喜欢

转载自blog.csdn.net/dkaily1314/article/details/88838285