SlideShare a Scribd company logo
Ring Documentation, Release 1.5.3
56.44 KeyPress and Mouse Move Events
In this example we will learn how to use the Events Filter to know about KeyPress and Mouse Move Events
Load "guilib.ring"
new qApp {
win1 = new qWidget()
{
setWindowTitle("Test using Event Filter!")
setGeometry(100,100,400,400)
setmousetracking(true)
myfilter = new qallevents(win1)
myfilter.setKeyPressEvent("pWork()")
myfilter.setMouseButtonPressevent("pClick()")
myfilter.setmousemoveevent("pMove()")
installeventfilter(myfilter)
show()
}
exec()
}
func pWork
win1.setwindowtitle('KeyPress! : ' + myfilter.getkeycode())
func pClick
new qmessagebox(win1) {
setgeometry(100,100,400,100)
setwindowtitle("click event!")
settext("x : " + myfilter.getx() +
" y : " + myfilter.gety() + " button : " +
myfilter.getbutton() )
show()
}
func pMove
win1.setwindowtitle("Mouse Move , X : " + myfilter.getx() +
" Y : " + myfilter.gety() )
The application during the runtime
56.44. KeyPress and Mouse Move Events 625
Ring Documentation, Release 1.5.3
56.45 Moving Objects using the Mouse
In the next example we will learn how to program movable objects where the user can move a label
Load "guilib.ring"
lPress = false
nX = 0
nY = 0
new qApp {
win1 = new qWidget()
{
setWindowTitle("Move this label!")
setGeometry(100,100,400,400)
setstylesheet("background-color:white;")
Label1 = new qLabel(Win1){
setGeometry(100,100,200,50)
setText("Welcome")
setstylesheet("font-size: 30pt")
myfilter = new qallevents(label1)
myfilter.setEnterevent("pEnter()")
myfilter.setLeaveevent("pLeave()")
56.45. Moving Objects using the Mouse 626
Ring Documentation, Release 1.5.3
myfilter.setMouseButtonPressEvent("pPress()")
myfilter.setMouseButtonReleaseEvent("pRelease()")
myfilter.setMouseMoveEvent("pMove()")
installeventfilter(myfilter)
}
show()
}
exec()
}
Func pEnter
Label1.setStyleSheet("background-color: purple; color:white;font-size: 30pt;")
Func pLeave
Label1.setStyleSheet("background-color: white; color:black;font-size: 30pt;")
Func pPress
lPress = True
nX = myfilter.getglobalx()
ny = myfilter.getglobaly()
Func pRelease
lPress = False
pEnter()
Func pMove
nX2 = myfilter.getglobalx()
ny2 = myfilter.getglobaly()
ndiffx = nX2 - nX
ndiffy = nY2 - nY
if lPress
Label1 {
move(x()+ndiffx,y()+ndiffy)
setStyleSheet("background-color: Green;
color:white;font-size: 30pt;")
nX = nX2
ny = nY2
}
ok
The application during the runtime
56.45. Moving Objects using the Mouse 627
Ring Documentation, Release 1.5.3
56.45. Moving Objects using the Mouse 628
Ring Documentation, Release 1.5.3
56.45. Moving Objects using the Mouse 629
Ring Documentation, Release 1.5.3
56.46 Inheritance from GUI Classes
Example :
Load "guilib.ring"
New MyWindow()
new qApp { exec() }
class mywindow from qwidget
Func init
super.init()
setwindowtitle("First Window")
setgeometry(100,100,400,400)
setstylesheet("background-color: purple;")
settooltip("my first window!")
show()
The application during the runtime
56.46. Inheritance from GUI Classes 630
Ring Documentation, Release 1.5.3
56.47 Using QDesktopWidget Class
In the next example we will learn about using the QDesktopWidget class
Load "guilib.ring"
New qApp {
win1 = New qWidget()
{
resize(400,400)
btn1 = new qPushbutton(win1)
{
setText("Center")
move(100,100)
resize(100,30)
setClickEvent("pCenter()")
}
Show()
}
exec()
}
Func pCenter
oDesktop = new qDesktopWidget()
56.47. Using QDesktopWidget Class 631
Ring Documentation, Release 1.5.3
oRect = oDesktop.screenGeometry( oDesktop.primaryScreen() )
win1.move((oRect.width()-win1.width()) /2 , (oRect.Height()-win1.Height())/2 )
win1.show()
The application during the runtime
56.48 Rotate Text
The next example rotate text using a Timer.
Load "guilib.ring"
nAngle = 0
New qapp {
win1 = new qwidget() {
setwindowtitle("Rotate Text")
resize(800,600)
label1 = new qlabel(win1) {
settext("")
myfilter = new qallevents(win1)
myfilter.setMouseButtonPressevent("pClick()")
installeventfilter(myfilter)
}
new qtimer(win1) {
setinterval(50)
56.48. Rotate Text 632
Ring Documentation, Release 1.5.3
settimeoutevent("pTime()")
start()
}
pDraw()
L1 = new qVBoxLayout() { AddWidget(Label1) } SetLayout(L1)
showMaximized()
}
exec()
}
Func pDraw
p1 = new qpicture()
color = new qcolor() {
setrgb(0,0,255,255)
}
pen = new qpen() {
setcolor(color)
setwidth(50)
}
painter = new qpainter() {
begin(p1)
setpen(pen)
myfont = font()
myfont.setpointsize(50)
setfont(myfont)
rotate(nAngle)
drawtext(350,0*nAngle,"welcome")
drawtext(0,0*nAngle,"welcome")
endpaint()
}
label1 {
setpicture(p1)
show()
}
Func pClick
win1 { setwindowtitle("Click Event") }
Func pTime
nAngle++
if nAngle = 90
nAngle = 10
ok
pDraw()
The application during the runtime
56.48. Rotate Text 633
Ring Documentation, Release 1.5.3
56.49 Change Focus
The next example change the focus using the ENTER key.
load "guilib.ring"
new qApp {
win = new qWidget() {
resize(600,600)
SetWindowTitle("Change Focus")
text1 = new qLineEdit(win)
text2 = new qLineEdit(win)
text3 = new qLineEdit(win)
text4 = new qLineEdit(win)
layout1 = new qVBoxLayout() {
AddWidget(text1)
AddWidget(text2)
AddWidget(text3)
AddWidget(text4)
}
setLayout(Layout1)
56.49. Change Focus 634

More Related Content

PDF
The Ring programming language version 1.3 book - Part 49 of 88
PDF
The Ring programming language version 1.7 book - Part 66 of 196
PDF
The Ring programming language version 1.9 book - Part 71 of 210
PDF
The Ring programming language version 1.5.2 book - Part 63 of 181
PDF
The Ring programming language version 1.8 book - Part 68 of 202
PDF
The Ring programming language version 1.5.4 book - Part 66 of 185
PDF
The Ring programming language version 1.5.2 book - Part 59 of 181
PDF
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.3 book - Part 49 of 88
The Ring programming language version 1.7 book - Part 66 of 196
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.5.2 book - Part 63 of 181
The Ring programming language version 1.8 book - Part 68 of 202
The Ring programming language version 1.5.4 book - Part 66 of 185
The Ring programming language version 1.5.2 book - Part 59 of 181
The Ring programming language version 1.7 book - Part 71 of 196

What's hot (20)

PDF
The Ring programming language version 1.8 book - Part 69 of 202
PDF
The Ring programming language version 1.7 book - Part 67 of 196
PDF
The Ring programming language version 1.5.3 book - Part 70 of 184
PDF
The Ring programming language version 1.5.4 book - Part 61 of 185
PDF
The Ring programming language version 1.4 book - Part 16 of 30
PDF
The Ring programming language version 1.8 book - Part 73 of 202
PDF
The Ring programming language version 1.9 book - Part 76 of 210
PDF
The Ring programming language version 1.5.1 book - Part 57 of 180
PDF
The Ring programming language version 1.5.1 book - Part 58 of 180
PDF
The Ring programming language version 1.6 book - Part 64 of 189
PDF
The Ring programming language version 1.7 book - Part 65 of 196
PDF
The Ring programming language version 1.5.2 book - Part 62 of 181
PDF
The Ring programming language version 1.10 book - Part 74 of 212
PDF
The Ring programming language version 1.5.3 book - Part 73 of 184
PDF
The Ring programming language version 1.8 book - Part 67 of 202
PDF
The Ring programming language version 1.7 book - Part 68 of 196
PDF
The Ring programming language version 1.5.4 book - Part 63 of 185
PDF
The Ring programming language version 1.9 book - Part 72 of 210
PDF
The Ring programming language version 1.8 book - Part 70 of 202
PDF
The Ring programming language version 1.2 book - Part 41 of 84
The Ring programming language version 1.8 book - Part 69 of 202
The Ring programming language version 1.7 book - Part 67 of 196
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.4 book - Part 61 of 185
The Ring programming language version 1.4 book - Part 16 of 30
The Ring programming language version 1.8 book - Part 73 of 202
The Ring programming language version 1.9 book - Part 76 of 210
The Ring programming language version 1.5.1 book - Part 57 of 180
The Ring programming language version 1.5.1 book - Part 58 of 180
The Ring programming language version 1.6 book - Part 64 of 189
The Ring programming language version 1.7 book - Part 65 of 196
The Ring programming language version 1.5.2 book - Part 62 of 181
The Ring programming language version 1.10 book - Part 74 of 212
The Ring programming language version 1.5.3 book - Part 73 of 184
The Ring programming language version 1.8 book - Part 67 of 202
The Ring programming language version 1.7 book - Part 68 of 196
The Ring programming language version 1.5.4 book - Part 63 of 185
The Ring programming language version 1.9 book - Part 72 of 210
The Ring programming language version 1.8 book - Part 70 of 202
The Ring programming language version 1.2 book - Part 41 of 84
Ad

Similar to The Ring programming language version 1.5.3 book - Part 76 of 184 (16)

PDF
The Ring programming language version 1.6 book - Part 68 of 189
PDF
The Ring programming language version 1.5.1 book - Part 62 of 180
PDF
The Ring programming language version 1.5 book - Part 11 of 31
PDF
The Ring programming language version 1.5.2 book - Part 61 of 181
PDF
The Ring programming language version 1.7 book - Part 69 of 196
PDF
The Ring programming language version 1.4.1 book - Part 18 of 31
PDF
The Ring programming language version 1.10 book - Part 77 of 212
PDF
The Ring programming language version 1.4 book - Part 17 of 30
PDF
The Ring programming language version 1.5.4 book - Part 64 of 185
PDF
The Ring programming language version 1.5.2 book - Part 60 of 181
PDF
The Ring programming language version 1.5.4 book - Part 62 of 185
PDF
The Ring programming language version 1.8 book - Part 71 of 202
PDF
The Ring programming language version 1.6 book - Part 65 of 189
PDF
The Ring programming language version 1.10 book - Part 73 of 212
PDF
The Ring programming language version 1.5.1 book - Part 59 of 180
PDF
The Ring programming language version 1.4.1 book - Part 17 of 31
The Ring programming language version 1.6 book - Part 68 of 189
The Ring programming language version 1.5.1 book - Part 62 of 180
The Ring programming language version 1.5 book - Part 11 of 31
The Ring programming language version 1.5.2 book - Part 61 of 181
The Ring programming language version 1.7 book - Part 69 of 196
The Ring programming language version 1.4.1 book - Part 18 of 31
The Ring programming language version 1.10 book - Part 77 of 212
The Ring programming language version 1.4 book - Part 17 of 30
The Ring programming language version 1.5.4 book - Part 64 of 185
The Ring programming language version 1.5.2 book - Part 60 of 181
The Ring programming language version 1.5.4 book - Part 62 of 185
The Ring programming language version 1.8 book - Part 71 of 202
The Ring programming language version 1.6 book - Part 65 of 189
The Ring programming language version 1.10 book - Part 73 of 212
The Ring programming language version 1.5.1 book - Part 59 of 180
The Ring programming language version 1.4.1 book - Part 17 of 31
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 192 of 212

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Teaching material agriculture food technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
sap open course for s4hana steps from ECC to s4
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology
Programs and apps: productivity, graphics, security and other tools
“AI and Expert System Decision Support & Business Intelligence Systems”
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The AUB Centre for AI in Media Proposal.docx

The Ring programming language version 1.5.3 book - Part 76 of 184

  • 1. Ring Documentation, Release 1.5.3 56.44 KeyPress and Mouse Move Events In this example we will learn how to use the Events Filter to know about KeyPress and Mouse Move Events Load "guilib.ring" new qApp { win1 = new qWidget() { setWindowTitle("Test using Event Filter!") setGeometry(100,100,400,400) setmousetracking(true) myfilter = new qallevents(win1) myfilter.setKeyPressEvent("pWork()") myfilter.setMouseButtonPressevent("pClick()") myfilter.setmousemoveevent("pMove()") installeventfilter(myfilter) show() } exec() } func pWork win1.setwindowtitle('KeyPress! : ' + myfilter.getkeycode()) func pClick new qmessagebox(win1) { setgeometry(100,100,400,100) setwindowtitle("click event!") settext("x : " + myfilter.getx() + " y : " + myfilter.gety() + " button : " + myfilter.getbutton() ) show() } func pMove win1.setwindowtitle("Mouse Move , X : " + myfilter.getx() + " Y : " + myfilter.gety() ) The application during the runtime 56.44. KeyPress and Mouse Move Events 625
  • 2. Ring Documentation, Release 1.5.3 56.45 Moving Objects using the Mouse In the next example we will learn how to program movable objects where the user can move a label Load "guilib.ring" lPress = false nX = 0 nY = 0 new qApp { win1 = new qWidget() { setWindowTitle("Move this label!") setGeometry(100,100,400,400) setstylesheet("background-color:white;") Label1 = new qLabel(Win1){ setGeometry(100,100,200,50) setText("Welcome") setstylesheet("font-size: 30pt") myfilter = new qallevents(label1) myfilter.setEnterevent("pEnter()") myfilter.setLeaveevent("pLeave()") 56.45. Moving Objects using the Mouse 626
  • 3. Ring Documentation, Release 1.5.3 myfilter.setMouseButtonPressEvent("pPress()") myfilter.setMouseButtonReleaseEvent("pRelease()") myfilter.setMouseMoveEvent("pMove()") installeventfilter(myfilter) } show() } exec() } Func pEnter Label1.setStyleSheet("background-color: purple; color:white;font-size: 30pt;") Func pLeave Label1.setStyleSheet("background-color: white; color:black;font-size: 30pt;") Func pPress lPress = True nX = myfilter.getglobalx() ny = myfilter.getglobaly() Func pRelease lPress = False pEnter() Func pMove nX2 = myfilter.getglobalx() ny2 = myfilter.getglobaly() ndiffx = nX2 - nX ndiffy = nY2 - nY if lPress Label1 { move(x()+ndiffx,y()+ndiffy) setStyleSheet("background-color: Green; color:white;font-size: 30pt;") nX = nX2 ny = nY2 } ok The application during the runtime 56.45. Moving Objects using the Mouse 627
  • 4. Ring Documentation, Release 1.5.3 56.45. Moving Objects using the Mouse 628
  • 5. Ring Documentation, Release 1.5.3 56.45. Moving Objects using the Mouse 629
  • 6. Ring Documentation, Release 1.5.3 56.46 Inheritance from GUI Classes Example : Load "guilib.ring" New MyWindow() new qApp { exec() } class mywindow from qwidget Func init super.init() setwindowtitle("First Window") setgeometry(100,100,400,400) setstylesheet("background-color: purple;") settooltip("my first window!") show() The application during the runtime 56.46. Inheritance from GUI Classes 630
  • 7. Ring Documentation, Release 1.5.3 56.47 Using QDesktopWidget Class In the next example we will learn about using the QDesktopWidget class Load "guilib.ring" New qApp { win1 = New qWidget() { resize(400,400) btn1 = new qPushbutton(win1) { setText("Center") move(100,100) resize(100,30) setClickEvent("pCenter()") } Show() } exec() } Func pCenter oDesktop = new qDesktopWidget() 56.47. Using QDesktopWidget Class 631
  • 8. Ring Documentation, Release 1.5.3 oRect = oDesktop.screenGeometry( oDesktop.primaryScreen() ) win1.move((oRect.width()-win1.width()) /2 , (oRect.Height()-win1.Height())/2 ) win1.show() The application during the runtime 56.48 Rotate Text The next example rotate text using a Timer. Load "guilib.ring" nAngle = 0 New qapp { win1 = new qwidget() { setwindowtitle("Rotate Text") resize(800,600) label1 = new qlabel(win1) { settext("") myfilter = new qallevents(win1) myfilter.setMouseButtonPressevent("pClick()") installeventfilter(myfilter) } new qtimer(win1) { setinterval(50) 56.48. Rotate Text 632
  • 9. Ring Documentation, Release 1.5.3 settimeoutevent("pTime()") start() } pDraw() L1 = new qVBoxLayout() { AddWidget(Label1) } SetLayout(L1) showMaximized() } exec() } Func pDraw p1 = new qpicture() color = new qcolor() { setrgb(0,0,255,255) } pen = new qpen() { setcolor(color) setwidth(50) } painter = new qpainter() { begin(p1) setpen(pen) myfont = font() myfont.setpointsize(50) setfont(myfont) rotate(nAngle) drawtext(350,0*nAngle,"welcome") drawtext(0,0*nAngle,"welcome") endpaint() } label1 { setpicture(p1) show() } Func pClick win1 { setwindowtitle("Click Event") } Func pTime nAngle++ if nAngle = 90 nAngle = 10 ok pDraw() The application during the runtime 56.48. Rotate Text 633
  • 10. Ring Documentation, Release 1.5.3 56.49 Change Focus The next example change the focus using the ENTER key. load "guilib.ring" new qApp { win = new qWidget() { resize(600,600) SetWindowTitle("Change Focus") text1 = new qLineEdit(win) text2 = new qLineEdit(win) text3 = new qLineEdit(win) text4 = new qLineEdit(win) layout1 = new qVBoxLayout() { AddWidget(text1) AddWidget(text2) AddWidget(text3) AddWidget(text4) } setLayout(Layout1) 56.49. Change Focus 634