Ring Documentation, Release 1.5.3
class GraphicsAppBase
display event_queue ev timeout
timer
redraw = true
FPS = 60
SCREEN_W = 1024
SCREEN_H = 700
KEY_UP = 1
KEY_DOWN = 2
KEY_LEFT = 3
KEY_RIGHT = 4
Key = [false,false,false,false]
Mouse_X = 0
Mouse_Y = 0
TITLE = "Graphics Application"
PRINT_MOUSE_XY = False
func start
SetUp()
loadResources()
eventsLoop()
destroy()
func setup
al_init()
al_init_font_addon()
al_init_ttf_addon()
al_init_image_addon()
al_install_audio()
al_init_acodec_addon()
al_reserve_samples(1)
al_set_new_display_flags(ALLEGRO_OPENGL)
display = al_create_display(SCREEN_W,SCREEN_H)
al_set_window_title(display,TITLE)
al_clear_to_color(al_map_rgb(0,0,0))
event_queue = al_create_event_queue()
al_register_event_source(event_queue,
al_get_display_event_source(display))
ev = al_new_allegro_event()
timeout = al_new_allegro_timeout()
al_init_timeout(timeout, 0.06)
timer = al_create_timer(1.0 / FPS)
al_register_event_source(event_queue,
al_get_timer_event_source(timer))
al_start_timer(timer)
al_install_mouse()
al_register_event_source(event_queue,
al_get_mouse_event_source())
al_install_keyboard()
al_register_event_source(event_queue,
al_get_keyboard_event_source())
func eventsLoop
while true
al_wait_for_event_until(event_queue, ev, timeout)
switch al_get_allegro_event_type(ev)
55.3. TicTacToe 3D Game 565
Ring Documentation, Release 1.5.3
on ALLEGRO_EVENT_DISPLAY_CLOSE
CloseEvent()
on ALLEGRO_EVENT_TIMER
redraw = true
on ALLEGRO_EVENT_MOUSE_AXES
mouse_x = al_get_allegro_event_mouse_x(ev)
mouse_y = al_get_allegro_event_mouse_y(ev)
if PRINT_MOUSE_XY
see "x = " + mouse_x + nl
see "y = " + mouse_y + nl
ok
on ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY
mouse_x = al_get_allegro_event_mouse_x(ev)
mouse_y = al_get_allegro_event_mouse_y(ev)
on ALLEGRO_EVENT_MOUSE_BUTTON_UP
MouseClickEvent()
on ALLEGRO_EVENT_KEY_DOWN
switch al_get_allegro_event_keyboard_keycode(ev)
on ALLEGRO_KEY_UP
key[KEY_UP] = true
on ALLEGRO_KEY_DOWN
key[KEY_DOWN] = true
on ALLEGRO_KEY_LEFT
key[KEY_LEFT] = true
on ALLEGRO_KEY_RIGHT
key[KEY_RIGHT] = true
off
on ALLEGRO_EVENT_KEY_UP
switch al_get_allegro_event_keyboard_keycode(ev)
on ALLEGRO_KEY_UP
key[KEY_UP] = false
on ALLEGRO_KEY_DOWN
key[KEY_DOWN] = false
on ALLEGRO_KEY_LEFT
key[KEY_LEFT] = false
on ALLEGRO_KEY_RIGHT
key[KEY_RIGHT] = false
on ALLEGRO_KEY_ESCAPE
exit
off
off
if redraw and al_is_event_queue_empty(event_queue)
redraw = false
drawScene()
al_flip_display()
ok
callgc()
end
func destroy
destroyResources()
al_destroy_timer(timer)
al_destroy_allegro_event(ev)
al_destroy_allegro_timeout(timeout)
al_destroy_event_queue(event_queue)
al_destroy_display(display)
al_exit()
55.3. TicTacToe 3D Game 566
Ring Documentation, Release 1.5.3
func loadresources
func drawScene
func destroyResources
func MouseClickEvent
exit # Exit from the Events Loop
func CloseEvent
exit # Exit from the Events Loop
Screen Shot:
55.3. TicTacToe 3D Game 567
CHAPTER
FIFTYSIX
DESKTOP AND MOBILE DEVELOPMENT USING RINGQT
In this chapter we will learn how to use the Qt framework classes in our Ring applications to create Desktop and
Mobile Applications.
56.1 The First GUI Application
In this example we will create an application to ask the user about his/her name. When the user type the name in the
textbox then click on “Say Hello” button, the textbox value will be updated by adding “Hello ” to the name.
Load "guilib.ring"
MyApp = New qApp {
win1 = new qWidget() {
setwindowtitle("Hello World")
setGeometry(100,100,370,250)
label1 = new qLabel(win1) {
settext("What is your name ?")
setGeometry(10,20,350,30)
setalignment(Qt_AlignHCenter)
}
btn1 = new qpushbutton(win1) {
setGeometry(10,200,100,30)
settext("Say Hello")
setclickevent("pHello()")
}
btn1 = new qpushbutton(win1) {
setGeometry(150,200,100,30)
settext("Close")
setclickevent("pClose()")
}
lineedit1 = new qlineedit(win1) {
setGeometry(10,100,350,30)
}
show()
}
568
Ring Documentation, Release 1.5.3
exec()
}
Func pHello
lineedit1.settext( "Hello " + lineedit1.text())
Func pClose
MyApp.quit()
Program Output:
At first we type the name in the textbox
Then we click on the say hello button
56.1. The First GUI Application 569
Ring Documentation, Release 1.5.3
56.2 Using Layout
The next example is just an upgrade to the previous application to use the vertical layout.
Load "guilib.ring"
MyApp = New qApp {
win1 = new qWidget() {
setwindowtitle("Hello World")
setGeometry(100,100,400,130)
label1 = new qLabel(win1) {
settext("What is your name ?")
setGeometry(10,20,350,30)
setalignment(Qt_AlignHCenter)
}
btn1 = new qpushbutton(win1) {
setGeometry(10,200,100,30)
settext("Say Hello")
setclickevent("pHello()")
}
btn2 = new qpushbutton(win1) {
setGeometry(150,200,100,30)
settext("Close")
setclickevent("pClose()")
}
lineedit1 = new qlineedit(win1) {
setGeometry(10,100,350,30)
}
layout1 = new qVBoxLayout() {
addwidget(label1)
addwidget(lineedit1)
addwidget(btn1)
addwidget(btn2)
}
win1.setlayout(layout1)
show()
}
exec()
}
Func pHello
lineedit1.settext( "Hello " + lineedit1.text())
Func pClose
MyApp.quit()
The application during the runtime!
56.2. Using Layout 570
Ring Documentation, Release 1.5.3
56.3 Using the QTextEdit Class
In this example we will use the QTextEdit Class
Load "guilib.ring"
New qApp {
win1 = new qWidget() {
setwindowtitle("QTextEdit Class")
setGeometry(100,100,500,500)
new qtextedit(win1) {
setGeometry(10,10,480,480)
}
show()
}
exec()
}
During the runtime we can paste rich text in the qtextedit widget
56.3. Using the QTextEdit Class 571
Ring Documentation, Release 1.5.3
56.4 Using the QListWidget Class
In this example we will use the QListWidget Class
Load "guilib.ring"
New qApp {
win1 = new qWidget() {
setGeometry(100,100,400,400)
list1 = new qlistwidget(win1) {
setGeometry(150,100,200,200)
alist = ["one","two","three","four","five"]
for x in alist additem(x) next
setcurrentrow(3,2)
win1.setwindowtitle("Items Count : " + count() )
}
56.4. Using the QListWidget Class 572
Ring Documentation, Release 1.5.3
btn1 = new qpushbutton(win1) {
setGeometry(10,200,100,30)
settext("selected item")
setclickevent("pWork()")
}
btn2 = new qpushbutton(win1) {
setGeometry(10,240,100,30)
settext("Delete item")
setclickevent("pWork2()")
}
show()
}
exec()
}
func pWork
btn1.settext(string(list1.currentrow()))
func pWork2
list1 {
takeitem(currentrow())
}
The application during the runtime
56.4. Using the QListWidget Class 573
Ring Documentation, Release 1.5.3
Another Example:
Load "guilib.ring"
New qApp {
win1 = new qWidget() {
setGeometry(100,100,500,400)
list1 = new qlistwidget(win1) {
setGeometry(150,100,200,200)
alist = ["one","two","three","four","five"]
for x in alist additem(x) next
setcurrentrow(3,2)
win1.setwindowtitle("Items Count : " + count() )
}
btn1 = new qpushbutton(win1) {
setGeometry(10,200,100,30)
settext("selected item")
setclickevent("pWork()")
}
btn2 = new qpushbutton(win1) {
setGeometry(10,240,100,30)
settext("Delete item")
setclickevent("pWork2()")
}
show()
}
exec()
}
func pWork
nbrOfItems = list1.count()
curItemNbr = list1.currentrow()
curValue = list1.item(list1.currentrow()).text()
win1.setwindowtitle( "After Select - NbrOfItems: " + nbrOfItems +
" CurItemNbr: " + curItemNbr + " CurValue: " + curValue )
btn1.settext( string(list1.currentrow() ) + " --- " +
list1.item(list1.currentrow()).text() )
func pWork2
list1 {
takeitem(currentrow())
nbrOfItems = count()
curItemNbr = currentrow()
curValue = item(currentrow()).text()
56.4. Using the QListWidget Class 574

More Related Content

PDF
The Ring programming language version 1.5.1 book - Part 57 of 180
PDF
The Ring programming language version 1.5.4 book - Part 66 of 185
PDF
The Ring programming language version 1.7 book - Part 66 of 196
PDF
The Ring programming language version 1.2 book - Part 41 of 84
PDF
The Ring programming language version 1.3 book - Part 46 of 88
PDF
The Ring programming language version 1.5.2 book - Part 63 of 181
PDF
The Ring programming language version 1.7 book - Part 71 of 196
PDF
The Ring programming language version 1.2 book - Part 46 of 84
The Ring programming language version 1.5.1 book - Part 57 of 180
The Ring programming language version 1.5.4 book - Part 66 of 185
The Ring programming language version 1.7 book - Part 66 of 196
The Ring programming language version 1.2 book - Part 41 of 84
The Ring programming language version 1.3 book - Part 46 of 88
The Ring programming language version 1.5.2 book - Part 63 of 181
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.2 book - Part 46 of 84

What's hot (20)

PDF
The Ring programming language version 1.2 book - Part 48 of 84
PDF
The Ring programming language version 1.3 book - Part 47 of 88
PDF
The Ring programming language version 1.5.3 book - Part 76 of 184
PDF
The Ring programming language version 1.8 book - Part 68 of 202
PDF
The Ring programming language version 1.5.4 book - Part 68 of 185
PDF
The Ring programming language version 1.4 book - Part 16 of 30
PDF
The Ring programming language version 1.2 book - Part 47 of 84
PDF
The Ring programming language version 1.5.2 book - Part 62 of 181
PDF
The Ring programming language version 1.10 book - Part 76 of 212
PDF
The Ring programming language version 1.5 book - Part 11 of 31
PDF
The Ring programming language version 1.8 book - Part 73 of 202
PDF
The Ring programming language version 1.5.2 book - Part 64 of 181
PDF
The Ring programming language version 1.10 book - Part 77 of 212
PDF
The Ring programming language version 1.9 book - Part 71 of 210
PDF
The Ring programming language version 1.5.2 book - Part 59 of 181
PDF
The Ring programming language version 1.5.4 book - Part 60 of 185
PDF
The Ring programming language version 1.7 book - Part 72 of 196
PDF
The Ring programming language version 1.8 book - Part 74 of 202
PDF
The Ring programming language version 1.4.1 book - Part 18 of 31
PDF
The Ring programming language version 1.8 book - Part 69 of 202
The Ring programming language version 1.2 book - Part 48 of 84
The Ring programming language version 1.3 book - Part 47 of 88
The Ring programming language version 1.5.3 book - Part 76 of 184
The Ring programming language version 1.8 book - Part 68 of 202
The Ring programming language version 1.5.4 book - Part 68 of 185
The Ring programming language version 1.4 book - Part 16 of 30
The Ring programming language version 1.2 book - Part 47 of 84
The Ring programming language version 1.5.2 book - Part 62 of 181
The Ring programming language version 1.10 book - Part 76 of 212
The Ring programming language version 1.5 book - Part 11 of 31
The Ring programming language version 1.8 book - Part 73 of 202
The Ring programming language version 1.5.2 book - Part 64 of 181
The Ring programming language version 1.10 book - Part 77 of 212
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.5.2 book - Part 59 of 181
The Ring programming language version 1.5.4 book - Part 60 of 185
The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.8 book - Part 74 of 202
The Ring programming language version 1.4.1 book - Part 18 of 31
The Ring programming language version 1.8 book - Part 69 of 202
Ad

Similar to The Ring programming language version 1.5.3 book - Part 70 of 184 (20)

PDF
The Ring programming language version 1.8 book - Part 67 of 202
PDF
The Ring programming language version 1.7 book - Part 65 of 196
PDF
The Ring programming language version 1.4.1 book - Part 16 of 31
PDF
The Ring programming language version 1.5.4 book - Part 67 of 185
PDF
The Ring programming language version 1.2 book - Part 45 of 84
PDF
The Ring programming language version 1.5.1 book - Part 62 of 180
PDF
The Ring programming language version 1.6 book - Part 68 of 189
PDF
The Ring programming language version 1.10 book - Part 74 of 212
PDF
The Ring programming language version 1.8 book - Part 70 of 202
PDF
The Ring programming language version 1.4.1 book - Part 17 of 31
PDF
The Ring programming language version 1.5.3 book - Part 75 of 184
PDF
The Ring programming language version 1.5.1 book - Part 58 of 180
PDF
The Ring programming language version 1.5.1 book - Part 64 of 180
PDF
The Ring programming language version 1.8 book - Part 71 of 202
PDF
The Ring programming language version 1.5.1 book - Part 60 of 180
PDF
The Ring programming language version 1.5.2 book - Part 61 of 181
PDF
The Ring programming language version 1.9 book - Part 78 of 210
PDF
The Ring programming language version 1.7 book - Part 69 of 196
PDF
The Ring programming language version 1.5.4 book - Part 64 of 185
PDF
The Ring programming language version 1.5.1 book - Part 63 of 180
The Ring programming language version 1.8 book - Part 67 of 202
The Ring programming language version 1.7 book - Part 65 of 196
The Ring programming language version 1.4.1 book - Part 16 of 31
The Ring programming language version 1.5.4 book - Part 67 of 185
The Ring programming language version 1.2 book - Part 45 of 84
The Ring programming language version 1.5.1 book - Part 62 of 180
The Ring programming language version 1.6 book - Part 68 of 189
The Ring programming language version 1.10 book - Part 74 of 212
The Ring programming language version 1.8 book - Part 70 of 202
The Ring programming language version 1.4.1 book - Part 17 of 31
The Ring programming language version 1.5.3 book - Part 75 of 184
The Ring programming language version 1.5.1 book - Part 58 of 180
The Ring programming language version 1.5.1 book - Part 64 of 180
The Ring programming language version 1.8 book - Part 71 of 202
The Ring programming language version 1.5.1 book - Part 60 of 180
The Ring programming language version 1.5.2 book - Part 61 of 181
The Ring programming language version 1.9 book - Part 78 of 210
The Ring programming language version 1.7 book - Part 69 of 196
The Ring programming language version 1.5.4 book - Part 64 of 185
The Ring programming language version 1.5.1 book - Part 63 of 180
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
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
Connector Corner: Transform Unstructured Documents with Agentic Automation
PDF
substrate PowerPoint Presentation basic one
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
Decision Optimization - From Theory to Practice
PDF
Ensemble model-based arrhythmia classification with local interpretable model...
PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
EIS-Webinar-Regulated-Industries-2025-08.pdf
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
PDF
4 layer Arch & Reference Arch of IoT.pdf
PDF
LMS bot: enhanced learning management systems for improved student learning e...
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
PDF
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
NewMind AI Weekly Chronicles – August ’25 Week IV
Data Virtualization in Action: Scaling APIs and Apps with FME
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Connector Corner: Transform Unstructured Documents with Agentic Automation
substrate PowerPoint Presentation basic one
Build automations faster and more reliably with UiPath ScreenPlay
Decision Optimization - From Theory to Practice
Ensemble model-based arrhythmia classification with local interpretable model...
Auditboard EB SOX Playbook 2023 edition.
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
EIS-Webinar-Regulated-Industries-2025-08.pdf
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
Co-training pseudo-labeling for text classification with support vector machi...
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
4 layer Arch & Reference Arch of IoT.pdf
LMS bot: enhanced learning management systems for improved student learning e...
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
Early detection and classification of bone marrow changes in lumbar vertebrae...

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

  • 1. Ring Documentation, Release 1.5.3 class GraphicsAppBase display event_queue ev timeout timer redraw = true FPS = 60 SCREEN_W = 1024 SCREEN_H = 700 KEY_UP = 1 KEY_DOWN = 2 KEY_LEFT = 3 KEY_RIGHT = 4 Key = [false,false,false,false] Mouse_X = 0 Mouse_Y = 0 TITLE = "Graphics Application" PRINT_MOUSE_XY = False func start SetUp() loadResources() eventsLoop() destroy() func setup al_init() al_init_font_addon() al_init_ttf_addon() al_init_image_addon() al_install_audio() al_init_acodec_addon() al_reserve_samples(1) al_set_new_display_flags(ALLEGRO_OPENGL) display = al_create_display(SCREEN_W,SCREEN_H) al_set_window_title(display,TITLE) al_clear_to_color(al_map_rgb(0,0,0)) event_queue = al_create_event_queue() al_register_event_source(event_queue, al_get_display_event_source(display)) ev = al_new_allegro_event() timeout = al_new_allegro_timeout() al_init_timeout(timeout, 0.06) timer = al_create_timer(1.0 / FPS) al_register_event_source(event_queue, al_get_timer_event_source(timer)) al_start_timer(timer) al_install_mouse() al_register_event_source(event_queue, al_get_mouse_event_source()) al_install_keyboard() al_register_event_source(event_queue, al_get_keyboard_event_source()) func eventsLoop while true al_wait_for_event_until(event_queue, ev, timeout) switch al_get_allegro_event_type(ev) 55.3. TicTacToe 3D Game 565
  • 2. Ring Documentation, Release 1.5.3 on ALLEGRO_EVENT_DISPLAY_CLOSE CloseEvent() on ALLEGRO_EVENT_TIMER redraw = true on ALLEGRO_EVENT_MOUSE_AXES mouse_x = al_get_allegro_event_mouse_x(ev) mouse_y = al_get_allegro_event_mouse_y(ev) if PRINT_MOUSE_XY see "x = " + mouse_x + nl see "y = " + mouse_y + nl ok on ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY mouse_x = al_get_allegro_event_mouse_x(ev) mouse_y = al_get_allegro_event_mouse_y(ev) on ALLEGRO_EVENT_MOUSE_BUTTON_UP MouseClickEvent() on ALLEGRO_EVENT_KEY_DOWN switch al_get_allegro_event_keyboard_keycode(ev) on ALLEGRO_KEY_UP key[KEY_UP] = true on ALLEGRO_KEY_DOWN key[KEY_DOWN] = true on ALLEGRO_KEY_LEFT key[KEY_LEFT] = true on ALLEGRO_KEY_RIGHT key[KEY_RIGHT] = true off on ALLEGRO_EVENT_KEY_UP switch al_get_allegro_event_keyboard_keycode(ev) on ALLEGRO_KEY_UP key[KEY_UP] = false on ALLEGRO_KEY_DOWN key[KEY_DOWN] = false on ALLEGRO_KEY_LEFT key[KEY_LEFT] = false on ALLEGRO_KEY_RIGHT key[KEY_RIGHT] = false on ALLEGRO_KEY_ESCAPE exit off off if redraw and al_is_event_queue_empty(event_queue) redraw = false drawScene() al_flip_display() ok callgc() end func destroy destroyResources() al_destroy_timer(timer) al_destroy_allegro_event(ev) al_destroy_allegro_timeout(timeout) al_destroy_event_queue(event_queue) al_destroy_display(display) al_exit() 55.3. TicTacToe 3D Game 566
  • 3. Ring Documentation, Release 1.5.3 func loadresources func drawScene func destroyResources func MouseClickEvent exit # Exit from the Events Loop func CloseEvent exit # Exit from the Events Loop Screen Shot: 55.3. TicTacToe 3D Game 567
  • 4. CHAPTER FIFTYSIX DESKTOP AND MOBILE DEVELOPMENT USING RINGQT In this chapter we will learn how to use the Qt framework classes in our Ring applications to create Desktop and Mobile Applications. 56.1 The First GUI Application In this example we will create an application to ask the user about his/her name. When the user type the name in the textbox then click on “Say Hello” button, the textbox value will be updated by adding “Hello ” to the name. Load "guilib.ring" MyApp = New qApp { win1 = new qWidget() { setwindowtitle("Hello World") setGeometry(100,100,370,250) label1 = new qLabel(win1) { settext("What is your name ?") setGeometry(10,20,350,30) setalignment(Qt_AlignHCenter) } btn1 = new qpushbutton(win1) { setGeometry(10,200,100,30) settext("Say Hello") setclickevent("pHello()") } btn1 = new qpushbutton(win1) { setGeometry(150,200,100,30) settext("Close") setclickevent("pClose()") } lineedit1 = new qlineedit(win1) { setGeometry(10,100,350,30) } show() } 568
  • 5. Ring Documentation, Release 1.5.3 exec() } Func pHello lineedit1.settext( "Hello " + lineedit1.text()) Func pClose MyApp.quit() Program Output: At first we type the name in the textbox Then we click on the say hello button 56.1. The First GUI Application 569
  • 6. Ring Documentation, Release 1.5.3 56.2 Using Layout The next example is just an upgrade to the previous application to use the vertical layout. Load "guilib.ring" MyApp = New qApp { win1 = new qWidget() { setwindowtitle("Hello World") setGeometry(100,100,400,130) label1 = new qLabel(win1) { settext("What is your name ?") setGeometry(10,20,350,30) setalignment(Qt_AlignHCenter) } btn1 = new qpushbutton(win1) { setGeometry(10,200,100,30) settext("Say Hello") setclickevent("pHello()") } btn2 = new qpushbutton(win1) { setGeometry(150,200,100,30) settext("Close") setclickevent("pClose()") } lineedit1 = new qlineedit(win1) { setGeometry(10,100,350,30) } layout1 = new qVBoxLayout() { addwidget(label1) addwidget(lineedit1) addwidget(btn1) addwidget(btn2) } win1.setlayout(layout1) show() } exec() } Func pHello lineedit1.settext( "Hello " + lineedit1.text()) Func pClose MyApp.quit() The application during the runtime! 56.2. Using Layout 570
  • 7. Ring Documentation, Release 1.5.3 56.3 Using the QTextEdit Class In this example we will use the QTextEdit Class Load "guilib.ring" New qApp { win1 = new qWidget() { setwindowtitle("QTextEdit Class") setGeometry(100,100,500,500) new qtextedit(win1) { setGeometry(10,10,480,480) } show() } exec() } During the runtime we can paste rich text in the qtextedit widget 56.3. Using the QTextEdit Class 571
  • 8. Ring Documentation, Release 1.5.3 56.4 Using the QListWidget Class In this example we will use the QListWidget Class Load "guilib.ring" New qApp { win1 = new qWidget() { setGeometry(100,100,400,400) list1 = new qlistwidget(win1) { setGeometry(150,100,200,200) alist = ["one","two","three","four","five"] for x in alist additem(x) next setcurrentrow(3,2) win1.setwindowtitle("Items Count : " + count() ) } 56.4. Using the QListWidget Class 572
  • 9. Ring Documentation, Release 1.5.3 btn1 = new qpushbutton(win1) { setGeometry(10,200,100,30) settext("selected item") setclickevent("pWork()") } btn2 = new qpushbutton(win1) { setGeometry(10,240,100,30) settext("Delete item") setclickevent("pWork2()") } show() } exec() } func pWork btn1.settext(string(list1.currentrow())) func pWork2 list1 { takeitem(currentrow()) } The application during the runtime 56.4. Using the QListWidget Class 573
  • 10. Ring Documentation, Release 1.5.3 Another Example: Load "guilib.ring" New qApp { win1 = new qWidget() { setGeometry(100,100,500,400) list1 = new qlistwidget(win1) { setGeometry(150,100,200,200) alist = ["one","two","three","four","five"] for x in alist additem(x) next setcurrentrow(3,2) win1.setwindowtitle("Items Count : " + count() ) } btn1 = new qpushbutton(win1) { setGeometry(10,200,100,30) settext("selected item") setclickevent("pWork()") } btn2 = new qpushbutton(win1) { setGeometry(10,240,100,30) settext("Delete item") setclickevent("pWork2()") } show() } exec() } func pWork nbrOfItems = list1.count() curItemNbr = list1.currentrow() curValue = list1.item(list1.currentrow()).text() win1.setwindowtitle( "After Select - NbrOfItems: " + nbrOfItems + " CurItemNbr: " + curItemNbr + " CurValue: " + curValue ) btn1.settext( string(list1.currentrow() ) + " --- " + list1.item(list1.currentrow()).text() ) func pWork2 list1 { takeitem(currentrow()) nbrOfItems = count() curItemNbr = currentrow() curValue = item(currentrow()).text() 56.4. Using the QListWidget Class 574