mirror of
https://github.com/mappu/miqt.git
synced 2025-01-04 06:38:38 +00:00
examples/subclass: show super() calls
This commit is contained in:
parent
40abeecd54
commit
0ff750727c
@ -7,20 +7,32 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
qt.NewQApplication(os.Args)
|
qt.NewQApplication(os.Args)
|
||||||
|
qt.QGuiApplication_SetApplicationDisplayName("Right-click to change color")
|
||||||
|
|
||||||
widget := qt.NewQWidget2()
|
w := qt.NewQGroupBox2() // qt.NewQw2()
|
||||||
widget.SetFixedWidth(320)
|
w.SetTitle("QGroupBox title")
|
||||||
widget.SetFixedHeight(240)
|
|
||||||
|
|
||||||
widget.OnPaintEvent(func(ev *qt.QPaintEvent) {
|
w.SetFixedWidth(320)
|
||||||
panic("xyz")
|
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()
|
defer ptr.Delete()
|
||||||
|
|
||||||
br := qt.NewQBrush12(qt.Black, qt.SolidPattern)
|
br := qt.NewQBrush12(useColors[currentColor], qt.SolidPattern)
|
||||||
defer br.Delete()
|
defer br.Delete()
|
||||||
|
|
||||||
ptr.SetBrush(br)
|
ptr.SetBrush(br)
|
||||||
@ -29,9 +41,14 @@ func main() {
|
|||||||
ptr.End()
|
ptr.End()
|
||||||
})
|
})
|
||||||
|
|
||||||
widget.Show()
|
w.OnContextMenuEvent(func(super func(ev *qt.QContextMenuEvent), ev *qt.QContextMenuEvent) {
|
||||||
widget.Repaint()
|
super(ev)
|
||||||
widget.Update()
|
|
||||||
|
currentColor = (currentColor + 1) % len(useColors)
|
||||||
|
w.Update() // repaints in next event loop tick
|
||||||
|
})
|
||||||
|
|
||||||
|
w.Show()
|
||||||
|
|
||||||
qt.QApplication_Exec()
|
qt.QApplication_Exec()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user