Sunteți pe pagina 1din 30

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()

51.4. Using the QListWidget Class 428


Ring Documentation, Release 1.4

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


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

51.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

51.5. Using QTreeView and QFileSystemModel 429


Ring Documentation, Release 1.4

51.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)

51.6. Using QTreeWidget and QTreeWidgetItem 430


Ring Documentation, Release 1.4

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

51.7 Using QComboBox Class

In this example we will learn about using the QComboBox class

51.7. Using QComboBox Class 431


Ring Documentation, Release 1.4

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

51.8 Creating Menubar

In this example we will learn about using the QMenuBar class

51.8. Creating Menubar 432


Ring Documentation, Release 1.4

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) {

51.8. Creating Menubar 433


Ring Documentation, Release 1.4

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

51.8. Creating Menubar 434


Ring Documentation, Release 1.4

51.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)

51.9. Creating Toolbar 435


Ring Documentation, Release 1.4

setFloatable(true)
}

show()
}

exec()
}

The application during the runtime

51.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)

51.10. Creating StatusBar 436


Ring Documentation, Release 1.4

setstatusbar(status1)
show()
}

exec()
}

The application during the runtime

51.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")

51.11. Using QDockWidget 437


Ring Documentation, Release 1.4

setGeometry(300,300,100,100)
}

label2 = new qlabel(win1) {


settext("How are you ?")
setGeometry(100,100,100,100)
}

dock1 = new qdockwidget(win1,0) {


setwidget(label1)
SetAllowedAreas(1)
}

dock2 = new qdockwidget(win1,0) {


setwidget(label2)
SetAllowedAreas(2)
}

adddockwidget(Qt_LeftDockWidgetArea,dock1,Qt_Horizontal)
adddockwidget(Qt_LeftDockWidgetArea,dock2,Qt_Vertical)

show()
}
exec()
}

The application during the runtime

51.11. Using QDockWidget 438


Ring Documentation, Release 1.4

51.12 Using QTabWidget

In this example we will learn about using the QTabWidget class


Load "guilib.ring"

New qApp {

win1 = new qMainWindow() {

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

page1 = new qwidget() {


new qpushbutton(page1) {
settext("The First Page")
}
}

page2 = new qwidget() {


new qpushbutton(page2) {
settext("The Second Page")
}
}

page3 = new qwidget() {


new qpushbutton(page3) {
settext("The Third Page")
}
}

tab1 = new qtabwidget(win1) {


inserttab(0,page1,"Page 1")
inserttab(1,page2,"Page 2")
inserttab(2,page3,"Page 3")
setGeometry(100,100,400,400)
}

status1 = new qstatusbar(win1) {


showmessage("Ready!",0)
}

setstatusbar(status1)
showMaximized()
}

exec()
}

The application during the runtime

51.12. Using QTabWidget 439


Ring Documentation, Release 1.4

51.13 Using QTableWidget

In this example we will learn about using the QTableWidget class


Load "guilib.ring"

New qApp {

win1 = new qMainWindow() {

setGeometry(100,100,1100,370)
setwindowtitle("Using QTableWidget")

Table1 = new qTableWidget(win1) {

setrowcount(10) setcolumncount(10)
setGeometry(0,0,800,400)
setselectionbehavior(QAbstractItemView_SelectRows)

for x = 1 to 10
for y = 1 to 10
item1 = new qtablewidgetitem("R"+X+"C"+Y)
setitem(x-1,y-1,item1)
next
next

setcentralwidget(table1)
show()

51.13. Using QTableWidget 440


Ring Documentation, Release 1.4

exec()
}

The application during the runtime

51.14 Using QProgressBar

In this example we will learn about using the QProgressBar class


Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {

setGeometry(100,100,600,150)
setwindowtitle("Using QProgressBar")

for x = 10 to 100 step 10


new qprogressbar(win1) {
setGeometry(100,x,350,30)
setvalue(x)
}
next

show()
}
exec()
}

The application during the runtime

51.14. Using QProgressBar 441


Ring Documentation, Release 1.4

51.15 Using QSpinBox

In this example we will learn about using the QSpinBox class


Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setGeometry(100,100,450,260)
setwindowtitle("Using QSpinBox")
new qspinbox(win1) {
setGeometry(50,100,350,30)
setvalue(50)
}
show()
}
exec()
}

The application during the runtime

51.15. Using QSpinBox 442


Ring Documentation, Release 1.4

51.16 Using QSlider

In this example we will learn about using the QSlider class


Load "guilib.ring"

New qApp {

win1 = new qMainWindow() {

setGeometry(100,100,500,400)
setwindowtitle("Using QSlider")

new qslider(win1) {
setGeometry(100,100,50,130)
settickinterval(50)
}

new qslider(win1) {
setGeometry(100,250,250,30)
settickinterval(50)
setorientation(Qt_Horizontal)
}

show()

exec()
}

The application during the runtime

51.16. Using QSlider 443


Ring Documentation, Release 1.4

51.17 Using QDateEdit

In this example we will learn about using the QDateEdit class


Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setwindowtitle("Using QDateEdit")
setGeometry(100,100,250,100)
new qdateedit(win1) {
setGeometry(20,40,220,30)
}
show()
}
exec()
}

The application during the runtime

51.17. Using QDateEdit 444


Ring Documentation, Release 1.4

51.18 Using QDial

In this example we will learn about using the QDial class


Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setGeometry(100,100,450,500)
setwindowtitle("Using QDial")
new qdial(win1) {
setGeometry(100,100,250,300)
}
show()
}
exec()
}

The application during the runtime

51.18. Using QDial 445


Ring Documentation, Release 1.4

Another Example
Load "guilib.ring"

New qApp {
win1 = new qMainWindow()
{
setGeometry(100,100,450,500)
setwindowtitle("Using QDial")
button1 = new QPushButton(win1){
setGeometry(100,350,100,30)
settext("Increment")
setClickEvent("pIncrement()")
}

button2 = new QPushButton(win1){


setGeometry(250,350,100,30)
settext("Decrement")
setClickEvent("pDecrement()")
}
pdial = new qdial(win1) {

51.18. Using QDial 446


Ring Documentation, Release 1.4

setGeometry(100,50,250,300)
setNotchesVisible(true)
setValue(50)
SetValueChangedEvent("pDialMove()")
}
lineedit1 = new qlineedit(win1) {
setGeometry(200,400,50,30)
setalignment(Qt_AlignHCenter)
settext(string(pdial.value()))
setreturnPressedEvent("pPress()")
}
show()
}
exec()
}

func pIncrement
pdial{val=value()}
pdial.setvalue(val+1)
lineedit1{settext(string(val+1))}

func pDecrement
pdial{val=value()}
pdial.setvalue(val-1)
lineedit1{settext(string(val-1))}

func pPress
lineedit1{val=text()}
pdial.setvalue(number(val))

func pDialMove
lineedit1.settext(""+pdial.value())

51.18. Using QDial 447


Ring Documentation, Release 1.4

51.19 Using QWebView

In this example we will learn about using the QWebView class


Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setwindowtitle("QWebView")
myweb = new qwebview(win1) {
setGeometry(10,10,600,600)
loadpage(new qurl("http://google.com"))
}
setcentralwidget(myweb)
showMaximized()
}
exec()
}

The application during the runtime

51.19. Using QWebView 448


Ring Documentation, Release 1.4

51.20 Using QCheckBox

In this example we will learn about using the QCheckBox class


Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setwindowtitle("Using QCheckBox")
new qcheckbox(win1) {
setGeometry(100,100,100,30)
settext("New Customer!")
}
showMaximized()
}
exec()
}

The application during the runtime

51.20. Using QCheckBox 449


Ring Documentation, Release 1.4

Another Example:
Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setGeometry(100,100,400,300)
setwindowtitle("Using QCheckBox")

### 0-Unchecked 1-Checked

CheckBox = new qcheckbox(win1) {


setGeometry(100,100,160,30)
settext("New Customer!")
setclickedEvent("HandleClickEvent()")
}

show()
}
exec()
}

Func HandleClickEvent

if CheckBox.isChecked() = 1
CheckBox.settext("New Customer. Check 1-ON")
else
CheckBox.settext("New Customer. Check 0-OFF")
ok

51.21 Using QRadioButton and QButtonGroup

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

51.21. Using QRadioButton and QButtonGroup 450


Ring Documentation, Release 1.4

New qApp {

win1 = new qMainWindow() {

setwindowtitle("Using QRadioButton")

new qradiobutton(win1) {
setGeometry(100,100,100,30)
settext("One")
}
new qradiobutton(win1) {
setGeometry(100,150,100,30)
settext("Two")
}
new qradiobutton(win1) {
setGeometry(100,200,100,30)
settext("Three")
}

group2 = new qbuttongroup(win1) {


btn4 = new qradiobutton(win1) {
setGeometry(200,150,100,30)
settext("Four")
}
btn5 = new qradiobutton(win1) {
setGeometry(200,200,100,30)
settext("Five")
}
addbutton(btn4,0)
addbutton(btn5,0)

showMaximized()

}
exec()
}

The application during the runtime

51.21. Using QRadioButton and QButtonGroup 451


Ring Documentation, Release 1.4

51.22 Adding Hyperlink to QLabel

In this example we will learn about creating Hyperlink using the QLabel class
Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setwindowtitle("QLabel - Hyperlink")
new qlabel(win1) {
setGeometry(100,100,100,30)
setopenexternallinks(true)
settext('<a href="http://google.com">Google</a>')
}
showMaximized()
}
exec()
}

The application during the runtime

51.22. Adding Hyperlink to QLabel 452


Ring Documentation, Release 1.4

51.23 QVideoWidget and QMediaPlayer

In this example we will learn about using the QVideoWidget and QMediaPlayer classes to play a group of movies
from different positions at the same time
Load "guilib.ring"

New qApp {

win1 = new qMainWindow() {

setwindowtitle("QVideoWidget")

btn1 = new qpushbutton(win1) {


setGeometry(0,0,100,30)
settext("play")
setclickevent("player.play() player2.play()
player3.play() player4.play()")
}

videowidget = new qvideowidget(win1) {


setGeometry(50,50,600,300)
setstylesheet("background-color: black")
}

videowidget2 = new qvideowidget(win1) {


setGeometry(700,50,600,300)
setstylesheet("background-color: black")
}

videowidget3 = new qvideowidget(win1) {


setGeometry(50,370,600,300)
setstylesheet("background-color: black")
}

videowidget4 = new qvideowidget(win1) {

51.23. QVideoWidget and QMediaPlayer 453


Ring Documentation, Release 1.4

setGeometry(700,370,600,300)
setstylesheet("background-color: black")
}

player = new qmediaplayer() {


setmedia(new qurl("1.mp4"))
setvideooutput(videowidget)
setposition(35*60*1000)

player2 = new qmediaplayer() {


setmedia(new qurl("2.mp4"))
setvideooutput(videowidget2)
setposition(23*60*1000)
}

player3 = new qmediaplayer() {


setmedia(new qurl("3.mp4"))
setvideooutput(videowidget3)
setposition(14.22*60*1000)
}

player4 = new qmediaplayer() {


setmedia(new qurl("4.avi"))
setvideooutput(videowidget4)
setposition(8*60*1000)
}

showfullscreen()

exec()

The application during the runtime

51.23. QVideoWidget and QMediaPlayer 454


Ring Documentation, Release 1.4

51.24 Using QFrame

In this example we will learn about using the QFrame class


Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setwindowtitle("Using QFrame")
for x = 0 to 10
frame1 = new qframe(win1,0) {
setGeometry(100,20+50*x,400,30)
setframestyle(QFrame_Raised | QFrame_WinPanel)
}
next
showMaximized()
}
exec()
}

The application during the runtime

51.24. Using QFrame 455


Ring Documentation, Release 1.4

51.25 Display Image using QLabel

In this example we will learn about displaying an image using the QLabel widget
Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setwindowtitle("QLabel - Display image")
new qlabel(win1) {
image = new qpixmap("b:/mahmoud/photo/advice.jpg")
setpixmap(image)
setGeometry(0,0,image.width(),image.height())
}

51.25. Display Image using QLabel 456


Ring Documentation, Release 1.4

showMaximized()
}
exec()
}

The application during the runtime

51.26 Menubar and StyleSheet Example

In this example we will learn about creating menubar and setting the window stylesheet
Load "guilib.ring"

New qApp {

51.26. Menubar and StyleSheet Example 457

S-ar putea să vă placă și