The Ring Programming Language Version 1.5 Book - Part 57 of 180

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Ring Documentation, Release 1.

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 535


Ring Documentation, Release 1.5

win1.setwindowtitle("After Delete - NbrOfItems: " + nbrOfItems +


" CurItemNbr: " + curItemNbr +" CurValue: " + curValue )
}

56.5 Using QTreeView and QFileSystemModel

In this example we will learn how to use the QTreeView widget to represent the File System
Load "guilib.ring"

New qApp {

win1 = New qWidget() {

setwindowtitle("Using QTreeView and QFileSystemModel")


setGeometry(100,100,500,400)

New qtreeview(win1) {
setGeometry(00,00,500,400)
oDir = new QDir()
ofile = new QFileSystemModel()
ofile.setrootpath(oDir.currentpath())
setmodel(ofile)
}

show()
}

exec()
}

The application during the runtime

56.5. Using QTreeView and QFileSystemModel 536


Ring Documentation, Release 1.5

56.6 Using QTreeWidget and QTreeWidgetItem

In this example we will learn about using the QTreeWidget and QTreeWidgetItem classes
Load "guilib.ring"

New qApp {

win1 = new qWidget() {

setwindowtitle("TreeWidget")
setGeometry(100,100,400,400)

layout1 = new qvboxlayout()

tree1 = new qtreewidget(win1) {


setGeometry(00,00,400,400)
setcolumncount(1)
myitem = new qtreewidgetitem()
myitem.settext(0,"The First Step")
addtoplevelitem(myitem)
for x = 1 to 10
myitem2 = new qtreewidgetitem()
myitem2.settext(0,"hello"+x)
myitem.addchild(myitem2)

56.6. Using QTreeWidget and QTreeWidgetItem 537


Ring Documentation, Release 1.5

for y = 1 to 10
myitem3 = new qtreewidgetitem()
myitem3.settext(0,"hello"+x)
myitem2.addchild(myitem3)
next
next
setheaderlabel("Steps Tree")
}

layout1.addwidget(tree1)
setlayout(layout1)

show()
}

exec()
}

The application during the runtime

56.7 Using QComboBox Class

In this example we will learn about using the QComboBox class

56.7. Using QComboBox Class 538


Ring Documentation, Release 1.5

Load "guilib.ring"

New qApp {

win1 = new qWidget() {

setwindowtitle("Using QComboBox")
setGeometry(100,100,400,400)

New QComboBox(win1) {
setGeometry(150,100,200,30)
alist = ["one","two","three","four","five"]
for x in aList additem(x,0) next
}

show()
}

exec()
}

The application during the runtime

56.8 Creating Menubar

In this example we will learn about using the QMenuBar class

56.8. Creating Menubar 539


Ring Documentation, Release 1.5

Load "guilib.ring"

MyApp = New qApp {

win1 = new qWidget() {

setwindowtitle("Using QMenubar")
setGeometry(100,100,400,400)

menu1 = new qmenubar(win1) {


sub1 = addmenu("File")
sub2 = addmenu("Edit")
sub3 = addmenu("Help")
sub1 {
oAction = new qAction(win1) {
settext("New")
}
addaction(oAction)
oAction = new qAction(win1) {
settext("Open")
}
addaction(oAction)
oAction = new qAction(win1) {
settext("Save")
}
addaction(oAction)
oAction = new qAction(win1) {
settext("Save As")
}
addaction(oAction)
addseparator()
oAction = new qaction(win1) {
settext("Exit")
setclickevent("myapp.quit()")
}
addaction(oAction)
}
sub2 {
oAction = new qAction(win1) {
settext("Cut")
}
addaction(oAction)
oAction = new qAction(win1) {
settext("Copy")
}
addaction(oAction)
oAction = new qAction(win1) {
settext("Paste")
}
addaction(oAction)
addseparator()
oAction = new qAction(win1) {
settext("Select All")
}
addaction(oAction)
}
sub3 {
oAction = new qAction(win1) {

56.8. Creating Menubar 540


Ring Documentation, Release 1.5

settext("Reference")
}
addaction(oAction)
sub4 = addmenu("Sub Menu")
sub4 {
oAction = new qAction(win1) {
settext("Website")
}
addaction(oAction)
oAction = new qAction(win1) {
settext("Forum")
}
addaction(oAction)
oAction = new qAction(win1) {
settext("Blog")
}
addaction(oAction)
}
addseparator()
oAction = new qAction(win1) {
settext("About")
}
addaction(oAction)
}
}
show()
}
exec()
}

The application during the runtime

56.8. Creating Menubar 541


Ring Documentation, Release 1.5

56.9 Creating Toolbar

In this example we will learn about using the QToolBar class


Load "guilib.ring"

New qApp {

win1 = new qMainWindow() {

setwindowtitle("Using QToolbar")
setGeometry(100,100,600,400)

abtns = [
new qpushbutton(win1) { settext("Add") } ,
new qpushbutton(win1) { settext("Edit") } ,
new qpushbutton(win1) { settext("Find") } ,
new qpushbutton(win1) { settext("Delete") } ,
new qpushbutton(win1) { settext("Exit")
setclickevent("win1.close()") }
]

tool1 = new qtoolbar(win1) {


for x in abtns addwidget(x) addseparator() next
setmovable(true)
setGeometry(0,0,500,30)

56.9. Creating Toolbar 542


Ring Documentation, Release 1.5

setFloatable(true)
}

show()
}

exec()
}

The application during the runtime

56.10 Creating StatusBar

In this example we will learn about using the QStatusBar class


Load "guilib.ring"

New qApp {

win1 = new qMainWindow() {

setwindowtitle("Using QStatusbar")
setGeometry(100,100,400,400)

status1 = new qstatusbar(win1) {


showmessage("Ready!",0)

56.10. Creating StatusBar 543


Ring Documentation, Release 1.5

setstatusbar(status1)
show()
}

exec()
}

The application during the runtime

56.11 Using QDockWidget

In this example we will learn about using the QDockWidget class


Load "guilib.ring"

New qApp {

win1 = new qMainWindow() {

setwindowtitle("QDockWidget")
setGeometry(100,100,400,400)

label1 = new qlabel(win1) {


settext("Hello")

56.11. Using QDockWidget 544

You might also like