qt
qt copied to clipboard
NewQImage LoadFromData broken
I'm trying to use embedded image file and render it on screen. But LoadFromData does not seems to work.
Is it a known issue?
Here is a example code.
package main
import (
"embed"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
"os"
)
//go:embed img.png
var bindata embed.FS
type MyWidget struct {
widget *widgets.QWidget
}
func New(parent *widgets.QWidget) *MyWidget {
w := widgets.NewQWidget(parent, core.Qt__Drawer)
myWidget := &MyWidget{widget: w}
myWidget.widget.ConnectPaintEvent(myWidget.paintEvent)
return myWidget
}
func (w *MyWidget) paintEvent(*gui.QPaintEvent) {
painter := gui.NewQPainter2(w.widget)
// This is not working. Even though the "by" variable does have the image content
by, _ := bindata.ReadFile("img.png")
im := gui.NewQImage()
im.LoadFromData(by, len(string(by)), "PNG")
painter.DrawImage8(core.NewQPoint2(0, 0), im)
// This is working fine
painter.DrawImage8(core.NewQPoint2(0, 0), gui.NewQImage9("img.png", "png"))
painter.DestroyQPainter()
}
func main() {
core.QCoreApplication_SetAttribute(core.Qt__AA_ShareOpenGLContexts, true)
widgets.NewQApplication(len(os.Args), os.Args)
mainWindow := widgets.NewQMainWindow(nil, 0)
myWidget := New(nil)
mainWindow.SetCentralWidget(myWidget.widget)
mainWindow.SetFixedSize2(800, 600)
mainWindow.Show()
widgets.QApplication_Exec()
}
I also have the same issue.
Has this issue been resolved? I'm encountering the same problem where QPixmap.LoadFromData is unable to load the content.