第二篇不知道写点啥,自己想用golang-qt重构一下自己写的项目,就把其中遇到的问题 都写下来吧,首先遇到的问题就是设置无边框的窗口,但是qt 设置无边框窗口之后就不能支持拖动之类的事件了,需要自己去实现一下,下面的代码就是我对设置无边框窗口的拖动的实现
mian函数:
package main import ( "os" "omc/ui/mainwindow" "github.com/therecipe/qt/widgets" ) func main() { widgets.NewQApplication(len(os.Args), os.Args) login := mainwindow.Newloginwindow(nil) login.Show() widgets.QApplication_Exec() }
无边框窗口(真的是啥都没有)
package mainwindow import ( "github.com/therecipe/qt/core" "github.com/therecipe/qt/gui" "github.com/therecipe/qt/widgets" ) type __loginwindow struct{} func (*__loginwindow) Init() {} type loginwindow struct { *__loginwindow *widgets.QWidget } var mouse_press bool var mouse_point core.QPoint func Newloginwindow(p widgets.QWidget_ITF) *loginwindow { var par *widgets.QWidget if p != nil { par = p.QWidget_PTR() } w := &loginwindow{QWidget: widgets.NewQWidget(par, 0)} w.Init() w.setupUI() return w } func (w *loginwindow) setupUI() { if w.ObjectName() == "" { w.SetObjectName("loginwindow") } w.Resize2(663, 450) w.retranslateUi() } func (w *loginwindow) retranslateUi() { //设置界面 w.SetWindowTitle("用户登录") w.SetWindowFlags(core.Qt__FramelessWindowHint) //链接信号对应的槽函数 w.ConnectMouseMoveEvent(w.mouseMove) w.ConnectMousePressEvent(w.mousePress) w.ConnectMouseReleaseEvent(w.mouseRelease) } func (w *loginwindow) mouseMove(event *gui.QMouseEvent) { if mouse_press { w.Move2(event.GlobalX()-mouse_point.X(), event.GlobalY()-mouse_point.Y()) } } func (w *loginwindow) mousePress(event *gui.QMouseEvent) { if event.Button() == core.Qt__LeftButton { mouse_press = true //mouse_point = event.GlobalPos() - loginwindow.Pos() mouse_point = *core.NewQPoint2(event.GlobalX()-w.X(), event.GlobalY()-w.Y()) } else if event.Button() == core.Qt__RightButton { w.Close() } } func (w *loginwindow) mouseRelease(event *gui.QMouseEvent) { mouse_press = false }
使用qt的设计器 在goqt这 实在是用的难受,手撸的代码