Sunteți pe pagina 1din 10

Ring Documentation, Release 1.5.

label1 = new qLabel(win1)


{
setText("Welcome")
setgeometry(10,10,200,50)
setstylesheet("color: purple ; font-size: 30pt;")
}

new qTimer(win1)
{
setInterVal(10)
setTimeOutEvent("pMove()")
start()
}

setWindowTitle("Movable Label")
setgeometry(100,100,600,80)
setStyleSheet("background-color: white;")
show()

exec()
}

Func pMove
label1
{
move(x()+1,y())
if x() > 600
move(10,y())
ok
}

The application during the runtime

55.40 QMessagebox Example

In this section we will learn how to check the output of the Message box
Load "guilib.ring"

new qApp {
win1 = new qWidget()
{
label1 = new qpushbutton(win1)
{
setText("Test")
setgeometry(10,10,200,50)

55.40. QMessagebox Example 585


Ring Documentation, Release 1.5.1

setstylesheet("color: purple ; font-size: 30pt;")


setclickevent("pWork()")
}
setWindowTitle("Messagebox")
setgeometry(100,100,600,80)
setStyleSheet("background-color: white;")
show()
}
exec()
}

func pWork
new qmessagebox(win1)
{
setwindowtitle("messagebox title")
settext("messagebox text")
setInformativeText("Do you want to save your changes?")
setstandardbuttons(QMessageBox_Yes | QMessageBox_No | QMessageBox_Close)
result = exec()
win1 {
if result = QMessageBox_Yes
setwindowtitle("Yes")
but result = QMessageBox_No
setwindowtitle("No")
but result = QMessageBox_Close
setwindowtitle("Close")
ok
}
}

The application during the runtime

55.41 Using QInputDialog Class

In the next example we will learn about using the QInputDialog class

55.41. Using QInputDialog Class 586


Ring Documentation, Release 1.5.1

Load "guilib.ring"

New QApp {

Win1 = New QWidget () {

SetGeometry(100,100,400,400)
SetWindowTitle("Input Dialog")

New QPushButton(win1)
{

SetText ("Input Dialog")


SetGeometry(100,100,100,30)
SetClickEvent("pWork()")
}

Show()
}

exec()
}

Func pWork
oInput = New QInputDialog(win1)
{
setwindowtitle("What is your name?")
setgeometry(100,100,400,50)
setlabeltext("User Name")
settextvalue("Mahmoud")
lcheck = exec()
if lCheck win1.setwindowtitle(oInput.textvalue()) ok
}

The application during the runtime

55.41. Using QInputDialog Class 587


Ring Documentation, Release 1.5.1

55.42 Dialog Functions

We have the next functions


SetDialogIcon(cIconFile)
MsgInfo(cTitle,cMessage)
ConfirmMsg(cTitle,cMessage) --> lResult
InputBox(cTitle,cMessage) --> cValue
InputBoxInt(cTitle,cMessage) --> nValue
InputBoxNum(cTitle,cMessage) --> nValue
InputBoxPass(cTitle,cMessage) --> cValue

Example
load "guilib.ring"

new qApp
{
SetDialogIcon("notepad.png")
msginfo(:Ring,:Welcome)
see confirmMsg(:Ring,"Are you sure?") + nl
see InputBoxNum(:Ring,"Enter Number(double) :") + nl
see InputBox(:Ring,"Enter Value :") + nl
see InputBoxInt(:Ring,"Enter Number(int)") + nl
see InputBoxPass(:Ring,"Enter Password") +nl
}

55.42. Dialog Functions 588


Ring Documentation, Release 1.5.1

55.43 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

55.43. KeyPress and Mouse Move Events 589


Ring Documentation, Release 1.5.1

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

55.44. Moving Objects using the Mouse 590


Ring Documentation, Release 1.5.1

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

55.44. Moving Objects using the Mouse 591


Ring Documentation, Release 1.5.1

55.44. Moving Objects using the Mouse 592


Ring Documentation, Release 1.5.1

55.44. Moving Objects using the Mouse 593


Ring Documentation, Release 1.5.1

55.45 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

55.45. Inheritance from GUI Classes 594

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