I'm using this Golang Qt binding here to create a simple code editor. I'm connecting a paintEvent
callback handler to the actual editor, in which I'm trying to do the painting. As I've found in various forums this is the only point when the painting should be done. However, when calling painter := gui.NewQPainter2(ce.editor)
I receive some warning outputs
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
and when calling the setPen
function I get the message
QPainter::setPen: Painter not active
Here is a working example of the issue
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()
}
You have not activated the QPainter instance. Check https://doc.qt.io/qt-5/qpainter.html#begin
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.