繁体   English   中英

Golang with Qt 问题与paintEvent 中的绘画

[英]Golang with Qt issue with painting in paintEvent

我在这里使用这个 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函数时,我收到消息

QPainter::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()
}

您尚未激活 QPainter 实例。 检查https://doc.qt.io/qt-5/qpainter.html#begin

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM