Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Golang与Qt在paintEvent中的绘画问题_Qt_Go - Fatal编程技术网

Golang与Qt在paintEvent中的绘画问题

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

我正在使用这个Golang Qt绑定来创建一个简单的代码编辑器。我正在将一个
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(…)
;但只是为了再次检查,我已经尝试包括它,我仍然有同样的问题