mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
examples/subclass: show super() calls
This commit is contained in:
parent
40abeecd54
commit
0ff750727c
@ -7,20 +7,32 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
qt.NewQApplication(os.Args)
|
||||
qt.QGuiApplication_SetApplicationDisplayName("Right-click to change color")
|
||||
|
||||
widget := qt.NewQWidget2()
|
||||
widget.SetFixedWidth(320)
|
||||
widget.SetFixedHeight(240)
|
||||
w := qt.NewQGroupBox2() // qt.NewQw2()
|
||||
w.SetTitle("QGroupBox title")
|
||||
|
||||
widget.OnPaintEvent(func(ev *qt.QPaintEvent) {
|
||||
panic("xyz")
|
||||
w.SetFixedWidth(320)
|
||||
w.SetFixedHeight(240)
|
||||
w.SetMinimumHeight(100)
|
||||
w.SetMinimumWidth(100)
|
||||
|
||||
ptr := qt.NewQPainter2(widget.QPaintDevice)
|
||||
useColors := []qt.GlobalColor{
|
||||
qt.Black, qt.Red, qt.Green, qt.Blue,
|
||||
}
|
||||
currentColor := 0
|
||||
|
||||
w.OnPaintEvent(func(super func(ev *qt.QPaintEvent), ev *qt.QPaintEvent) {
|
||||
// Call the base class's PaintEvent to get initial content
|
||||
// (Comment this out to see the QGroupBox disappear)
|
||||
super(ev)
|
||||
|
||||
// Then, draw on top of it
|
||||
ptr := qt.NewQPainter2(w.QPaintDevice)
|
||||
defer ptr.Delete()
|
||||
|
||||
br := qt.NewQBrush12(qt.Black, qt.SolidPattern)
|
||||
br := qt.NewQBrush12(useColors[currentColor], qt.SolidPattern)
|
||||
defer br.Delete()
|
||||
|
||||
ptr.SetBrush(br)
|
||||
@ -29,9 +41,14 @@ func main() {
|
||||
ptr.End()
|
||||
})
|
||||
|
||||
widget.Show()
|
||||
widget.Repaint()
|
||||
widget.Update()
|
||||
w.OnContextMenuEvent(func(super func(ev *qt.QContextMenuEvent), ev *qt.QContextMenuEvent) {
|
||||
super(ev)
|
||||
|
||||
currentColor = (currentColor + 1) % len(useColors)
|
||||
w.Update() // repaints in next event loop tick
|
||||
})
|
||||
|
||||
w.Show()
|
||||
|
||||
qt.QApplication_Exec()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user