Golang与Qt在paintEvent中的绘画问题
我正在使用这个Golang Qt绑定来创建一个简单的代码编辑器。我正在将一个Golang与Qt在paintEvent中的绘画问题,qt,go,Qt,Go,我正在使用这个Golang Qt绑定来创建一个简单的代码编辑器。我正在将一个paintEvent回调处理程序连接到实际的编辑器,我正试图在其中进行绘制。正如我在各种论坛上发现的,这是唯一一个应该完成绘画的地方。 但是,当调用painter:=gui.NewQPainter2(ce.editor)时,我收到一些警告输出 QWidget::paintEngine: Should no longer be called QPainter::begin: Paint device returned en
paintEvent
回调处理程序连接到实际的编辑器,我正试图在其中进行绘制。正如我在各种论坛上发现的,这是唯一一个应该完成绘画的地方。
但是,当调用painter:=gui.NewQPainter2(ce.editor)
时,我收到一些警告输出
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
当调用setPen
函数时,我会收到消息
QPaint::setPen:画师未激活
下面是一个关于这个问题的工作示例
package main
import (
"os"
"github.com/therecipe/qt/widgets"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/core"
)
type CodeEditor struct {
editor *widgets.QPlainTextEdit
}
func NewCodeEditor(parent *widgets.QWidget) *CodeEditor {
codeEditor := &CodeEditor{editor: widgets.NewQPlainTextEdit(parent)}
codeEditor.setupSignals()
return codeEditor
}
func (ce *CodeEditor) setupSignals() {
ce.editor.ConnectPaintEvent(ce.paintEvent)
}
func (ce *CodeEditor) paintEvent(event *gui.QPaintEvent) {
painter := gui.NewQPainter2(ce.editor)
color := gui.NewQColor6("red")
painter.SetPen2(color)
painter.DestroyQPainter()
}
func main() {
core.QCoreApplication_SetAttribute(core.Qt__AA_ShareOpenGLContexts, true)
widgets.NewQApplication(len(os.Args), os.Args)
mainWindow := widgets.NewQMainWindow(nil, 0)
codeEditor := NewCodeEditor(nil)
mainWindow.SetCentralWidget(codeEditor.editor)
mainWindow.ShowMaximized()
widgets.QApplication_Exec()
}
您尚未激活QPaint实例。
选中则
NewQPainter2
将自动执行该操作,因此不需要显式的begin(…)
;但只是为了再次检查,我已经尝试包括它,我仍然有同样的问题