195
Go home Go back to other tutorials HBQT-Tutorial Giovanni Di Maria - [email protected] since: Feb 12, 2011 Tutorial Harbour QT Classes This Tutorial: Rev. [1] - February 12, 2011 Rev. [7477] - Feb 10, 2013 Index News and latest updates Record of Revision Introduction Notes for developers Installing Harbour and QT Building Harbour and QT HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp 1 de 195 13/02/2013 18:56

HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

Embed Size (px)

Citation preview

Page 1: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

Go homeGo back to other tutorials

HBQT-Tutorial

Giovanni Di Maria - [email protected]: Feb 12, 2011

TutorialHarbour QT Classes

This Tutorial:Rev. [1] - February 12, 2011Rev. [7477] - Feb 10, 2013

Index

News and latest updatesRecord of RevisionIntroductionNotes for developersInstalling Harbour and QTBuilding Harbour and QT

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

1 de 195 13/02/2013 18:56

Page 2: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

Compiling in WindowLegal Notices

QMainWindowQWidgetQApplicationQIconQDateEditQTimeEditQCalendarWidgetQLabelQMessageBoxQPushButtonQStatusBarQCursorQTabWidgetQTimerQSSQMenuUIQTableWidgetQInputDialogQColorDialogQProgressBarHTMLQSliderQDialQSpinBoxQComboBoxQFontComboBoxQLCDNumberQRadioButtonQVBoxLayoutQHBoxLayoutQLineEditQTextEditQEventQPainterQTreeViewQResourceQScrollAreaQDialogQToolBarQFileDialogQCheckBox

QSAY, QGET, QREAD and friends

Games

Sample ApplicationsSample applications with Databases

Appendix A - PhotosAppendix B - ContributorsAppendix C - What users thinkAppendix D - Communities

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

2 de 195 13/02/2013 18:56

Page 3: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

News and latest updatesAdded: QSAY, QGET, QREAD and friendsAdded: QSAY, QGET, QREAD and friends: SetfocusAdded: QSAY, QGET, QREAD and friends: Changing a fieldAdded: QSAY, QGET, QREAD and friends: Area of rectangleAdded: Photo

Record of RevisionRevision Date1 Feb 12, 20111000 Mar 22, 20112000 Mar 30, 20113000 Apr 03, 20114000 Apr 21, 20115000 Jun 07, 20126000 Jul 09, 20127000 Nov 29, 2012

IntroductionThis tutorial is a brief, continuously updated, of the use of the classes QT with Harbourlanguage. It is specifically written for beginners that initially encountered some difficultiesin using these classes, however, extremely powerful and efficient. The approach of thetutorial is different from other guides that are online. It simply focuses a single class orsingle object, so you do not get lost in the maze of the vast files of examples providedwith the product. This will easily learn to manage and plan their individual class, asneeded, and, finally, to put "together" the whole.Giovanni Di Maria

Notes for developers

In order to make good use of the Qt classes, you should see the include file"hbqtgui.ch"You should consult the Digia's offcial documentationIf possible, you must NOT use static variablesIt is strongly recommended to use hbformat tool to format the .prg sourcesTo create a source, you can copy and paste the code into your text editor and saveit with .prg extensionWhen you connect an object with a Signal, if must be passed as string withoutspaces.Example: oButton1:Connect( "clicked()", { || QApplication():quit() } )When you connect an object with a Event, if must be passed as constant.Example: oWnd:connect( QEvent_KeyPress , { |k| keypressed( k ) } )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

3 de 195 13/02/2013 18:56

Page 4: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

How to install Harbour and QtContribsFollow these steps to install Harbour and QtContribs into your computer:

Download and install Harbour Nightly from http://sourceforge.net/projects/harbour-project/files/binaries-windows/nightly/Download and install QtContribs from http://sourceforge.net/projects/qtcontribs/files/Enjoy !!!

How to build Harbour and QT ClassesYou must install QT classes into your computer.You must also install Harbour nightly, in order to use "gcc" compiler.Here is a general batch to build Harbour and QT classes:

timecd c:\c:\Programmi\Subversion\bin\svn checkout https://harbour-project.svn.sourceforge.net/svnroot/harbour-project/trunk/path c:\hb32\comp\mingw\binset HB_INSTALL_PREFIX=c:\harbourcd c:\harbourwin-make.exe clean install

c:\Programmi\Subversion\bin\svn checkout svn://svn.code.sf.net/p/qtcontribs/code/trunk c:\harbour\addonspath c:\harbour\bin;c:\hb32\comp\mingw\binset HB_WITH_QT=c:\Qt\4.8.3\includecd c:\harbour\addonshbmk2 qtcontribs.hbptime

Compiling in WindowsIn order to compile correctly your sources, you must follow this procedure:

Create the file named sample.hbp (or other name) as follow:hbqt.hbc-w3 -es2sample.prgotherprogrs.prg

1.

Create your source program, named sample.prg (or other name).2.Compile with hbmk2 sample.hbp.3.The procedure will create the file sample.exe.4.You can distribute your program with the following files:

sample.exeharbour-32.dlllibgcc_s_dw2-1.dllmingwm10.dllQtCore4.dllQtGui4.dll

5.

Legal NoticesThis tutorial is a free document and will remain free. You can view, use, print and

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

4 de 195 13/02/2013 18:56

Page 5: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

redistribute it and/or modify it, without any limitations.

QMainWindow - WindowThe following example shows how to create a simple main window. The window isresizable.

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oWnd:show() QApplication():exec()

RETURN

QMainWindow - Window not resizableThe following example shows how to create a simple main window. The window is NOTresizable.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

5 de 195 13/02/2013 18:56

Page 6: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:setFixedSize( 200, 200 )

oWnd:show() QApplication():exec()

RETURN

QMainWindow - Window with fixed widthThe following example shows how to create a simple main window. The width is lockedand the height is resizable.

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:setFixedWidth( 500 )

oWnd:show() QApplication():exec()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

6 de 195 13/02/2013 18:56

Page 7: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QMainWindow - Window with Fixed heightThe following example shows how to create a simple main window. The height is lockedand the width is resizable.

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:setFixedHeight( 300 )

oWnd:show() QApplication():exec()

RETURN

QMainWindow - Blinking Title BarThe following example shows how to create a blinking title bar.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

7 de 195 13/02/2013 18:56

Page 8: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oClock

oWnd := QMainWindow() oWnd:resize( 300, 200 ) oWnd:setWindowTitle( "Finestra di Giovanni" )

oClock := QTimer() oClock:Connect( "timeout()", { || toggle( oWnd ) } ) oClock:start( 500 )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE toggle( o )

IF o:WindowTitle == "Finestra di Giovanni" o:setWindowTitle( "" ) ELSE o:setWindowTitle( "Finestra di Giovanni" ) ENDIF

RETURN

QMainWindow - Colored Window (QSS)The following example shows how to create a colored main window, using QSS.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

8 de 195 13/02/2013 18:56

Page 9: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oWnd:setStyleSheet( " background-color: #CCCCFF; " ) oWnd:show() QApplication():exec()

RETURN

QMainWindow - Colored Window (QPalette)The following example shows how to create a colored main window, using Qpalette.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oPalette

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oPalette := QPalette() oPalette:SetColor( QPalette_Window, QColor( 255,200,200 ) ) oWnd:setPalette( oPalette )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

9 de 195 13/02/2013 18:56

Page 10: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:show() QApplication():exec()

RETURN

QMainWindow - Window with backgroundThe following example shows how to create a window with a background from an image.

PROCEDURE Main()

LOCAL oWnd, oButton

oWnd := QMainWindow() oWnd:SetFixedSize( 400, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" ) oWnd:setStyleSheet( "background-image: url(01.png) " );

oButton := QPushButton( oWnd ) oButton:setText( "Press" ) oButton:move( 150, 50 ) oButton:setStyleSheet( " background: #F4F4F0; " )

oWnd:show() QApplication():exec()

RETURN

QMainWindow - Window as Splash ScreenThe following example shows how to create a Splash Screen Window. There is NOborder. The windows is closed by pressing on it.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

10 de 195 13/02/2013 18:56

Page 11: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel

oWnd := QWidget() oWnd:setWindowTitle( "Special Effect" ) oWnd:resize( 300, 300 ) oWnd:setAttribute( Qt_WA_TranslucentBackground ) oWnd:setWindowFlags( Qt_FramelessWindowHint )

oLabel := QLabel( oWnd ) oLabel:move( 0, 0 ) oLabel:resize( 300, 300 ) oLabel:setText( "Click me to close!" ) oLabel:setStyleSheet( "border: 1px solid #0000FF; background-color: yellow; border-radius: 150px;" ) oLabel:setAlignment( Qt_AlignHCenter + Qt_AlignVCenter ) oLabel:Connect( QEvent_MouseButtonPress, { || QApplication():quit() } )

oWnd:show() QApplication():exec()

RETURN

QMainWindow - Colored Window (QSS) with a gradientThe following example shows how to create a colored main window, with a gradient,using QSS.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

11 de 195 13/02/2013 18:56

Page 12: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oWnd:setStyleSheet( "background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #8888FF, stop:1 #000033);" oWnd:show() QApplication():exec()

RETURN

QMainWindow - Retrieve version of Harbour, GCC and QTThe following example shows how to retrieve informations from compilers used.

#include "hbver.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel1, oLabel2, oLabel3 LOCAL cVersion1, cVersion2, cVersion3

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

12 de 195 13/02/2013 18:56

Page 13: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

cVersion1 := hb_Version ( HB_VERSION_HARBOUR ) cVersion2 := hb_Version ( HB_VERSION_COMPILER ) cVersion3 := qVersion()

oLabel1 := QLabel( oWnd ) oLabel1:resize( 360, 30 ) oLabel1:move( 20, 50 ) oLabel1:setStyleSheet( "background-color : yellow;" ) oLabel1:setText( "Harbour version: " + "<font color=red>" + cVersion1 + "</font>" )

oLabel2 := QLabel( oWnd ) oLabel2:resize( 360, 30 ) oLabel2:move( 20, 100 ) oLabel2:setStyleSheet( "background-color : yellow;" ) oLabel2:setText( "GCC version: " + "<font color=red>" + cVersion2 + "</font>" )

oLabel3 := QLabel( oWnd ) oLabel3:resize( 360, 30 ) oLabel3:move( 20, 150 ) oLabel3:setStyleSheet( "background-color : yellow;" ) oLabel3:setText( "QT version: " + "<font color=red>" + cVersion3 + "</font>" )

oWnd:show() QApplication():exec()

RETURN

QWidget - Widgets in a Main WindowThe following example shows how to create some widgets in a main window. Thewidgets contain buttons. If you have to move the buttons, simply move the widget only.The Main Window is the parent of the widgets. The widgets are the parent of thebuttons.

PROCEDURE Main()

LOCAL oWnd LOCAL oGroup1,oGroup2,oGroup3 LOCAL oButton1,oButton2,oButton3 LOCAL oButton4,oButton5,oButton6 LOCAL oButton7,oButton8,oButton9

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 650, 400 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

13 de 195 13/02/2013 18:56

Page 14: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oGroup1 := QWidget(oWnd) oGroup1:resize( 150, 300 ) oGroup1:move( 50, 50 ) oGroup1:setStyleSheet( " background: #CCCCFF; " )

oGroup2 := QWidget(oWnd) oGroup2:resize( 150, 300 ) oGroup2:move( 250, 50 ) oGroup2:setStyleSheet( " background: #CCFFCC; " )

oGroup3 := QWidget(oWnd) oGroup3:resize( 150, 300 ) oGroup3:move( 450, 50 ) oGroup3:setStyleSheet( " background: #FFCCCC; " )

oButton1 := QPushButton( oGroup1 ) oButton1:setText( "Push" ) oButton1:move( 25, 50 ) oButton1:resize( 100, 30 ) oButton1:setStyleSheet( " background: #FFAAAA; " )

oButton2 := QPushButton( oGroup1 ) oButton2:setText( "Push" ) oButton2:move( 25, 100 ) oButton2:resize( 100, 30 ) oButton2:setStyleSheet( " background: #AAFFAA; " )

oButton3 := QPushButton( oGroup1 ) oButton3:setText( "Push" ) oButton3:move( 25, 150 ) oButton3:resize( 100, 30 ) oButton3:setStyleSheet( " background: #AAAAFF; " )

oButton4 := QPushButton( oGroup2 ) oButton4:setText( "Push" ) oButton4:move( 25, 50 ) oButton4:resize( 100, 30 ) oButton4:setStyleSheet( " background: #FFAAAA; " )

oButton5 := QPushButton( oGroup2 ) oButton5:setText( "Push" ) oButton5:move( 25, 100 ) oButton5:resize( 100, 30 ) oButton5:setStyleSheet( " background: #AAFFAA; " )

oButton6 := QPushButton( oGroup2 ) oButton6:setText( "Push" ) oButton6:move( 25, 150 ) oButton6:resize( 100, 30 ) oButton6:setStyleSheet( " background: #AAAAFF; " )

oButton7 := QPushButton( oGroup3 ) oButton7:setText( "Push" ) oButton7:move( 25, 50 ) oButton7:resize( 100, 30 ) oButton7:setStyleSheet( " background: #FFAAAA; " )

oButton8 := QPushButton( oGroup3 ) oButton8:setText( "Push" ) oButton8:move( 25, 100 ) oButton8:resize( 100, 30 ) oButton8:setStyleSheet( " background: #AAFFAA; " )

oButton9 := QPushButton( oGroup3 ) oButton9:setText( "Push" ) oButton9:move( 25, 150 ) oButton9:resize( 100, 30 ) oButton9:setStyleSheet( " background: #AAAAFF; " )

oWnd:show() QApplication():exec()

RETURN

QApplication - BeepThe following example shows how to create a simple main window, as application. At

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

14 de 195 13/02/2013 18:56

Page 15: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

exit, the application produces a beep. This method sounds the bell, using the defaultvolume and sound. The function is not available in Qt for Embedded Linux.

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:SetFixedSize( 200, 200 ) oWnd:setWindowTitle( "Giovanni" )

oWnd:show() QApplication():exec()

QApplication():beep()

RETURN

QApplication - Quitting from applicationThe following example shows how to quit from an application, using a method.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

15 de 195 13/02/2013 18:56

Page 16: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oButton1, oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 300, 200 )

oButton1 := QPushButton( oWnd ) oButton1:setText( "Quit" ) oButton1:move( 50, 50 ) oButton1:Connect( "clicked()", { || QApplication():quit() } )

oWnd:show() QApplication():exec()

RETURN

QIcon - Widget with IconThe following example shows how to add an icon to a widget.

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni with icon" ) oWnd:resize( 500, 200 ) oWnd:setwindowicon( QIcon( "harbour-icon.png" ) )

oWnd:show() QApplication():exec()

RETURN

QDateEdit - Editing a dateThe following example shows how to enter and edit a date.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

16 de 195 13/02/2013 18:56

Page 17: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oDate oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oDate := QDateEdit( oWnd ) oDate:move( 60, 30 )

oWnd:show() QApplication():exec()

RETURN

QDateEdit - Editing a date and displaying the week dayThe following example shows how to enter and edit a date. The program shows also theweek day of the date.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

17 de 195 13/02/2013 18:56

Page 18: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oDate, oText

SET DATE italian oWnd := QMainWindow() oWnd:SetFixedSize( 400, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oDate := QDateEdit( oWnd ) oDate:resize( 200, 30 ) oDate:move( 50, 50 ) oDate:Connect( "dateChanged(QDate)" , { |x|oText:setText( CDOW(CToD(oDate:text(x ) ) ) ) } )

oText := QLabel( oWnd ) oText:setText( "Change the date" ) oText:resize( 200, 30 ) oText:move( 80, 100 )

oWnd:show() QApplication():exec()

RETURN

QDateEdit - How to show current dateBy default QDateEdit shows the date 01/01/2000. You can show the actual date using

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

18 de 195 13/02/2013 18:56

Page 19: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

setdate() function.

PROCEDURE Main()

LOCAL oWnd, oDate

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 200, 100 )

oDate := QDateEdit( oWnd ) oDate:move( 60, 20 ) oDate:SetDate ( QDate( Year( Date() ), Month( Date() ), Day( Date() ) ) )

oWnd:show() QApplication():exec()

RETURN

QTimeEdit - Editing the timeThe following example shows how to enter the time.

PROCEDURE Main()

LOCAL oWnd LOCAL oSetting

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

19 de 195 13/02/2013 18:56

Page 20: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:resize( 250, 150 )

oSetting := QTimeEdit( oWnd ) oSetting:move( 100, 50 )

oWnd:show() QApplication():exec()

RETURN

QCalendarWidget - Simple CalendarThe following example shows how to create a simple window containing a calendar.

PROCEDURE Main()

LOCAL oWnd LOCAL oCalendar

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oCalendar := QCalendarWidget( oWnd ) oCalendar:resize( 250, 200 ) oCalendar:move( 50, 50 ) oCalendar:setFirstDayOfWeek( 1 ) oCalendar:setGridVisible( .T. )

oWnd:show() QApplication():exec()

RETURN

QCalendarWidget - Interactive CalendarThe following example shows how to create a simple window containing an interactive

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

20 de 195 13/02/2013 18:56

Page 21: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

calendar. The buttons allow to navigate through the months and to show or hide thegrid.

PROCEDURE Main()

LOCAL oWnd LOCAL oCal LOCAL oBPrev, oBNext, oBGrid

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oCal := QCalendarWidget( oWnd ) oCal:resize( 300, 200 ) oCal:move( 50, 50 ) oCal:setFirstDayOfWeek( 1 ) oCal:setGridVisible( .T. )

oBPrev := QPushButton( oWnd ) oBPrev:setText( "Prev Month" ) oBPrev:move( 100, 5 ) oBPrev:resize( 90, 25 ) oBPrev:Connect( "clicked()", { || oCal:showPreviousMonth() } )

oBNext := QPushButton( oWnd ) oBNext:setText( "Next Month" ) oBNext:move( 200, 5 ) oBNext:resize( 90, 25 ) oBNext:Connect( "clicked()", { || oCal:showNextMonth() } )

oBGrid := QPushButton( oWnd ) oBGrid:setText( "Show/Hide Grid" ) oBGrid:move( 100, 260 ) oBGrid:resize( 200, 25 ) oBGrid:Connect( "clicked()", { || oCal:setGridVisible( ! oCal:isGridVisible() ) } )

oWnd:show() QApplication():exec()

RETURN

QCalendarWidget - Setting a date

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

21 de 195 13/02/2013 18:56

Page 22: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

This example shows how to set any date in the calendar.

PROCEDURE Main()

LOCAL oWnd LOCAL oCalendar

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oCalendar := QCalendarWidget( oWnd ) oCalendar:resize( 250, 200 ) oCalendar:move( 50, 50 ) oCalendar:setFirstDayOfWeek( 1 ) oCalendar:setGridVisible( .T. ) oCalendar:setSelectedDate( QDate( 1967, 1, 7 ) )

oWnd:show() QApplication():exec()

RETURN

QLabel - Text LabelThe following example shows how to create a simple main window with a label, used astext string.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

22 de 195 13/02/2013 18:56

Page 23: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oText

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oText := QLabel( oWnd ) oText:setText( "Hello World" ) oText:move( 100, 100 )

oWnd:show() QApplication():exec()

RETURN

QLabel - ImageThe following example shows how to view an image, using the QLabel class.

PROCEDURE Main()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

23 de 195 13/02/2013 18:56

Page 24: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

LOCAL oWnd LOCAL oImg

oWnd := QMainWindow() oWnd:SetFixedSize( 400, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oImg := QLabel( oWnd ) oImg:move( 50, 50 ) oImg:resize( 300, 200 ) oImg:SetPixmap( QPixmap( "sample.png" ) ) oImg:setStyleSheet( "border: 2px solid #0000ff;" )

oWnd:show() QApplication():exec()

RETURN

QLabel - Colored Text Label (QSS)The following example shows how to create a simple main window with a label used astext string. The label is colored using QSS.

PROCEDURE Main()

LOCAL oWnd LOCAL oText

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oText := QLabel( oWnd ) oText:setStyleSheet( "background-color : yellow; color : red;" ) oText:setText( "Hello World" ) oText:move( 100, 100 )

oWnd:show() QApplication():exec()

RETURN

QLabel - Colored Text Label (QPalette)The following example shows how to create a simple main window with a label used as

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

24 de 195 13/02/2013 18:56

Page 25: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

text string. The label is colored using QPalette.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oPalette LOCAL oText

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oPalette := QPalette() oPalette:SetColor( QPalette_WindowText, QColor( 255,0,0 ) )

oText := QLabel( oWnd ) oText:setPalette( oPalette ) oText:setText( "Hello World" ) oText:move( 100, 100 )

oWnd:show() QApplication():exec()

RETURN

QLabel - Colored Text Label (HTML)The following example shows how to create a simple main window with a label used astext string. The label is colored and formatted using HTML.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

25 de 195 13/02/2013 18:56

Page 26: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oText LOCAL cString

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 500, 300 )

cString := "Hello World <br><br>" cString := cString + "This is a complex text, colored and formatted " cString := cString + "by HTML. <br><br>" cString := cString + "<FONT color=#FF0000>RED</FONT><br>" cString := cString + "<FONT color=#008800>GREEN</FONT><br>" cString := cString + "<FONT color=#0000FF>BLUE</FONT><br><br>" cString := cString + "<b>Bold Text</b> <br>" cString := cString + "<i>Italic Text</i> <br>" cString := cString + "<u>Underlined Text</u> <br"

oText := QLabel( oWnd ) oText:setText( cString ) oText:move( 0, 0 ) oText:resize( 500, 300 )

oWnd:show() QApplication():exec()

RETURN

QLabel - Circular LabelThe following example shows how to create a circular label. The label is colored andformatted using QSS.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

26 de 195 13/02/2013 18:56

Page 27: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel

oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oLabel := QLabel( oWnd ) oLabel:move( 50, 50 ) oLabel:resize( 100, 100 ) oLabel:setText( "79" ) oLabel:setStyleSheet( "border: 1px solid #0000FF; background-color: yellow; border-radius: 50px;" ) oLabel:setAlignment( Qt_AlignHCenter + Qt_AlignVCenter )

oWnd:show() QApplication():exec()

RETURN

QLabel - Horizontal lineThe following example shows how to simulate a horizontal line. A good solution is tocreate a label with a thickness of 1 or 2 pixels.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

27 de 195 13/02/2013 18:56

Page 28: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel, oLabel2

oWnd := QMainWindow() oWnd:SetFixedSize( 400, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oLabel := QLabel( oWnd ) oLabel:move( 25, 100 ) oLabel:resize( 350, 1 ) oLabel:setStyleSheet( "background-color: black" )

oLabel2 := QLabel( oWnd ) oLabel2:move( 25, 200 ) oLabel2:resize( 350, 2 ) oLabel2:setStyleSheet( "background-color: black" )

oWnd:show() QApplication():exec()

RETURN

QLabel - Vertical lineThe following example shows how to simulate a vertical line. A good so- lution is tocreate a label with a thickness of 1 or 2 pixels.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

28 de 195 13/02/2013 18:56

Page 29: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel, oLabel2

oWnd := QMainWindow() oWnd:SetFixedSize( 400, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oLabel := QLabel( oWnd ) oLabel:move( 150, 25 ) oLabel:resize( 1, 250 ) oLabel:setStyleSheet( "background-color: black" )

oLabel2 := QLabel( oWnd ) oLabel2:move( 250, 25 ) oLabel2:resize( 2, 250 ) oLabel2:setStyleSheet( "background-color: black" )

oWnd:show() QApplication():exec()

RETURN

QLabel - Grid of linesThe following example shows how to simulate grid of lines. A good solution is to createtwo arrays of labels, with a thickness of 1 or 2 pixels. The first array is used for horizontallines, the second array is used for vertical lines.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

29 de 195 13/02/2013 18:56

Page 30: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oHorizontalLine[12], oVerticalLine[6] LOCAL oNumber[11,5] LOCAL nR, nC, nN

oWnd := QMainWindow() oWnd:SetFixedSize( 500, 600 ) oWnd:setWindowTitle( "Finestra Giovanni" )

nN := 0 for nR := 1 TO 11 for nC := 1 TO 5 nN ++ oNumber[nR,nC] := QLabel( oWnd ) oNumber[nR,nC]:setStyleSheet( "border: 1px solid #0000FF; background-color: #FFFF88; border-radius: 20px; oNumber[nR,nC]:setText( "<b>" + AllTrim( Str(nN ) ) + "</b>" ) oNumber[nR,nC]:move( nC * 60 + 50, nR * 50 - 25 ) oNumber[nR,nC]:resize( 40, 40 ) oNumber[nR,nC]:setAlignment( Qt_AlignHCenter + Qt_AlignVCenter ) next nC next nR

for nR := 1 TO 12 oHorizontalLine[nR] := QLabel( oWnd ) oHorizontalLine[nR]:resize( 300, 1 ) oHorizontalLine[nR]:move( 100, nR * 50 - 30 ) oHorizontalLine[nR]:setStyleSheet( "background-color:#000000;" ) next nR

for nC := 1 TO 6 oVerticalLine[nC] := QLabel( oWnd ) oVerticalLine[nC]:resize( 1, 550 ) oVerticalLine[nC]:move( nC * 60 + 40, 20 ) oVerticalLine[nC]:setStyleSheet( "background-color:#000000;" ) next nC

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

30 de 195 13/02/2013 18:56

Page 31: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:show() QApplication():exec()

RETURN

QLabel - Modify the FramesThe following example shows how to change the frame of the labels.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oText1, oText2, oText3

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 250 )

oText1 := QLabel( oWnd ) oText1:setText( "Hello World" ) oText1:move( 100, 50 ) oText1:setFrameStyle( QFrame_Box )

oText2 := QLabel( oWnd ) oText2:setText( "Hello World" ) oText2:move( 100, 100 ) oText2:setFrameStyle( QFrame_Raised + QFrame_Panel )

oText3 := QLabel( oWnd ) oText3:setText( "Hello World" ) oText3:move( 100, 150 ) oText3:setFrameStyle( QFrame_Sunken + QFrame_Panel )

oWnd:show() QApplication():exec()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

31 de 195 13/02/2013 18:56

Page 32: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QLabel - AlignmentThe following example shows how to align a text in a QLabel.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oText1, oText2, oText3

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 250 )

oText1 := QLabel( oWnd ) oText1:setText( "Hello World" ) oText1:move( 100, 50 ) oText1:setFrameStyle( QFrame_Box ) oText1:setAlignment( Qt_AlignLeft + Qt_AlignTop )

oText2 := QLabel( oWnd ) oText2:setText( "Hello World" ) oText2:move( 100, 100 ) oText2:setFrameStyle( QFrame_Box ) oText2:setAlignment( Qt_AlignHCenter + Qt_AlignVCenter )

oText3 := QLabel( oWnd ) oText3:setText( "Hello World" ) oText3:move( 100, 150 ) oText3:setFrameStyle( QFrame_Box ) oText3:setAlignment( Qt_AlignRight + Qt_AlignBottom )

oWnd:show() QApplication():exec()

RETURN

QLabel - Setting a numberThe following example shows how to set a number in a QLabel, without the use ofstrings.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

32 de 195 13/02/2013 18:56

Page 33: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oText1

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 150 )

oText1 := QLabel( oWnd ) oText1:setNum( 2011 ) oText1:move( 100, 50 ) oText1:setFrameStyle( QFrame_Box ) oText1:setAlignment( Qt_AlignCenter )

oWnd:show() QApplication():exec()

RETURN

QLabel - RectangleThe following example shows how to create a green rectangle with a QLabel.

PROCEDURE Main()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

33 de 195 13/02/2013 18:56

Page 34: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

LOCAL oWnd LOCAL oRectangle

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oRectangle := QLabel( oWnd ) oRectangle:resize( 300, 200 ) oRectangle:move( 50, 50 ) oRectangle:setStyleSheet( "background-color: green;" )

oWnd:show() QApplication():exec()

RETURN

QLabel - Showing an image from InternetThe following example shows how to view an image from Internet. You can download theimage from Internet and store it into your hard disk. Then you can show it as a localimage. You have to link the program against hbtip library.

PROCEDURE Main()

LOCAL oWnd, oImg LOCAL oHttp, cString

oHttp := TIPClientHTTP():new( "http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-101.png" ) oHttp:open() cString := oHttp:readAll() oHttp:close() hb_MemoWrit( "televideo.png", cString )

oWnd := QMainWindow()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

34 de 195 13/02/2013 18:56

Page 35: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:SetFixedSize( 700, 500 ) oWnd:setStyleSheet( " background-color: #CCCCFF; " ) oWnd:setWindowTitle( "Giovanni" )

oImg := QLabel( oWnd ) oImg:move( 28, 50 ) oImg:resize( 644, 400 ) oImg:SetPixmap( QPixmap( "televideo.png" ) )

oWnd:show() QApplication():exec()

RETURN

QMessageBox - Message Box (simple)The following example shows how to create a simple window with an active button. If thebutton is pressed, a message box appears.

PROCEDURE Main()

LOCAL oWnd LOCAL oButton1

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oButton1 := QPushButton( oWnd ) oButton1:setText( "Press for message" ) oButton1:resize( 300, 50 ) oButton1:move( 50, 50 ) oButton1:Connect( "clicked()", { || message() } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE message()

LOCAL oBox

oBox := QMessageBox() oBox:setInformativeText( "attention!!! " )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

35 de 195 13/02/2013 18:56

Page 36: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oBox:setWindowTitle( "Informazione" )

oBox:exec()

RETURN

QMessageBox - Message Box (Yes and No buttons)The following example shows how to create a simple window with the Yes and Nobutton. If the Yes button is pressed, the window title changes.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd,oButton1

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 180 )

oButton1 := QPushButton( oWnd ) oButton1:setText( "Press to change title" ) oButton1:resize( 300, 50 ) oButton1:move( 50, 50 ) oButton1:Connect( "clicked()", { || MsgYesNo(oWnd) } )

oWnd:show() QApplication():exec()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

36 de 195 13/02/2013 18:56

Page 37: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE MsgYesNo(oW)

LOCAL oMB, nButtonPressed

oMB := QMessageBox() oMB:setInformativeText( "Ok to change the Window Title ?" ) oMB:setWindowTitle( "Information" ) oMB:setWindowFlags( Qt_Dialog ) oMB:setStandardButtons( QMessageBox_Yes + QMessageBox_No ) oMB:setDefaultButton( QMessageBox_Yes )

nButtonPressed := oMB:exec()

IF nButtonPressed == QMessageBox_Yes oW:setWindowTitle( "Title changed" ) ENDIF

RETURN

QPushButton - Simple buttonThe following example shows how to create a simple button. If pressed, the window willbe resized.

PROCEDURE Main()

LOCAL oButton1, oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 400, 300 )

oButton1 := QPushButton( oWnd ) oButton1:setText( "Resize Window" ) oButton1:move( 50, 50 ) oButton1:Connect( "clicked()", { || edit( oWnd ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE edit( oWnd )

oWnd:resize( 500, 400 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

37 de 195 13/02/2013 18:56

Page 38: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

RETURN

QPushButton - Button with iconThe following example shows how to create a simple button with a icon. If pressed, thetitle bar changes.

PROCEDURE Main()

LOCAL oButton2, oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 400, 300 )

oButton2 := QPushButton( oWnd ) oButton2:setText( "Press to change title bar" ) oButton2:move( 50, 100 ) oButton2:setIcon( QIcon( "star.png" ) ) oButton2:resize( 300, 50 ) oButton2:Connect( "clicked()", { || edit( oWnd ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE edit( oWnd )

oWnd:setWindowTitle( "Ok, changed" )

RETURN

QPushButton - ButtonsThe following example shows how to create a simple window with two active buttons. Ifthe first button is pressed, the window closes. If the second button is pressed, the title ofthe window changes his value.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

38 de 195 13/02/2013 18:56

Page 39: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oButton1, oButton2, oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Prova dei pulsanti" ) oWnd:resize( 640, 480 )

oButton1 := QPushButton( oWnd ) oButton1:setText( "Quit" ) oButton1:move( 50, 50 ) oButton1:Connect( "clicked()", { || QApplication():quit() } )

oButton2 := QPushButton( oWnd ) oButton2:setText( "Premere per modificare la barra del titolo" ) oButton2:move( 50, 100 ) oButton2:setIcon( QIcon( "star.png" ) ) oButton2:resize( 300, 50 ) oButton2:Connect( "clicked()", { || edit( oWnd ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE edit( oWnd )

oWnd:setWindowTitle( "Evviva, ci sono riuscito !!!!!!!!!" )

RETURN

QPushButton - Array of ButtonsThe following example shows how to create many buttons, stored in an array. Thebuttons have no actions.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

39 de 195 13/02/2013 18:56

Page 40: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oButton[13] LOCAL k oWnd := QMainWindow() oWnd:SetFixedSize( 300, 450 ) oWnd:setWindowTitle( "Finestra Giovanni" )

for k := 1 TO 13 oButton[k] := QPushButton( oWnd ) oButton[k]:resize( 150, 25 ) oButton[k]:move( 75, 30 * k ) oButton[k]:setText( "Button " + AllTrim( Str(k ) ) ) next k

oWnd:show() QApplication():exec()

RETURN

QPushButton - Array of Buttons with variable dimensionsThe following example shows how to create many buttons, stored in an array. Theirdimension is set by an incremental variable.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

40 de 195 13/02/2013 18:56

Page 41: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oButton[13] LOCAL k oWnd := QMainWindow() oWnd:SetFixedSize( 300, 450 ) oWnd:setWindowTitle( "Finestra Giovanni" )

for k := 1 TO 13 oButton[k] := QPushButton( oWnd ) oButton[k]:resize( 150 + ( k * 5 ), 25 ) oButton[k]:move( 40, 30 * k ) oButton[k]:setText( "Button " + AllTrim( Str(k ) ) ) next k

oWnd:show() QApplication():exec()

RETURN

QPushButton - Button TipsThe following example shows how to create a button with the tip.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

41 de 195 13/02/2013 18:56

Page 42: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oButton1

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 300, 200 )

oButton1 := QPushButton( oWnd ) oButton1:setText( "Press" ) oButton1:move( 50, 50 ) oButton1:setToolTip( "This is an help that explains the function of the button" )

oWnd:show() QApplication():exec()

RETURN

QPushButton - Button that plays a Wav fileThe following example shows how to create a button to miaow a cat.

PROCEDURE Main()

LOCAL oButton1, oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

42 de 195 13/02/2013 18:56

Page 43: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:resize( 300, 200 ) oButton1 := QPushButton( oWnd ) oButton1:setText( "Cat" ) oButton1:move( 50, 50 ) oButton1:Connect( "clicked()", { || cat( ) } ) oWnd:show() QApplication():exec()

RETURN

PROCEDURE cat()

QSound( "cat.wav" ):play()

RETURN

QPushButton - Array of Buttons that change the title bar (1)The following example shows how to create many buttons, stored in an array. Everybutton changes the title bar, showing its progressive number. This example does not usethe macro.

PROCEDURE Main()

LOCAL oButton[13] LOCAL k LOCAL oWnd

oWnd := QMainWindow() oWnd:SetFixedSize( 300, 450 ) oWnd:setWindowTitle( "Finestra Giovanni" )

for k := 1 TO 13 oButton[k] := QPushButton( oWnd ) oButton[k]:resize( 150, 25 ) oButton[k]:move( 75, 30 * k ) oButton[k]:setText( "Button " + hb_ntos( k ) )

oButton[k]:Connect( "clicked()", TitleBlock( oWnd, k ) ) next k

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

43 de 195 13/02/2013 18:56

Page 44: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:show() QApplication():exec()

RETURN

STATIC FUNCTION TitleBlock( oWnd, k )

RETURN { || oWnd:setWindowTitle( Str( k ) ) }

QPushButton - Array of Buttons that change the title bar (2)The following example shows how to create many buttons, stored in an array. Everybutton changes the title bar, showing its progressive number. This example uses themacro. It uses also a PRIVATE variable. The use of MEMVAR, PUBLIC or PRIVATEvariables is a very bad practice and no (new) component should ever _require_ suchpractice.

PROCEDURE Main() LOCAL oButton[13] LOCAL k LOCAL cAction

MEMVAR oWnd

oWnd := QMainWindow() oWnd:SetFixedSize( 300, 450 ) oWnd:setWindowTitle( "Finestra Giovanni" )

for k := 1 TO 13 oButton[k] := QPushButton( oWnd ) oButton[k]:resize( 150, 25 ) oButton[k]:move( 75, 30 * k ) oButton[k]:setText( "Button " + hb_ntos( k ) )

cAction := "{|| change_title( oWnd , " + hb_ntos( k ) + " )}" oButton[k]:Connect( "clicked()", &( cAction ) ) next k

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

44 de 195 13/02/2013 18:56

Page 45: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:show() QApplication():exec()

RETURN

PROCEDURE change_title( oW, cNumber )

oW:setWindowTitle( Str( cNumber ) )

RETURN

QPushButton - Array of Buttons that change the title bar (3)The following example shows how to create many buttons, stored in an array. Everybutton changes the title bar, showing its progressive number. This example does not usethe macro. The buttons are created in a FOR loop, but the Connection is createdmanually, one for each button.

PROCEDURE Main()

LOCAL oWnd LOCAL oButton[13] LOCAL k

oWnd := QMainWindow() oWnd:SetFixedSize( 300, 450 ) oWnd:setWindowTitle( "Finestra Giovanni" )

for k := 1 TO 13 oButton[k] := QPushButton( oWnd ) oButton[k]:resize( 150, 25 ) oButton[k]:move( 75, 30 * k ) oButton[k]:setText( "Button " + hb_ntos( k ) ) next k

oButton[1]:Connect( "clicked()", { || oWnd:setWindowTitle( "1" ) } ) oButton[2]:Connect( "clicked()", { || oWnd:setWindowTitle( "2" ) } ) oButton[3]:Connect( "clicked()", { || oWnd:setWindowTitle( "3" ) } ) oButton[4]:Connect( "clicked()", { || oWnd:setWindowTitle( "4" ) } ) oButton[5]:Connect( "clicked()", { || oWnd:setWindowTitle( "5" ) } )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

45 de 195 13/02/2013 18:56

Page 46: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oButton[6]:Connect( "clicked()", { || oWnd:setWindowTitle( "6" ) } ) oButton[7]:Connect( "clicked()", { || oWnd:setWindowTitle( "7" ) } ) oButton[8]:Connect( "clicked()", { || oWnd:setWindowTitle( "8" ) } ) oButton[9]:Connect( "clicked()", { || oWnd:setWindowTitle( "9" ) } ) oButton[10]:Connect( "clicked()", { || oWnd:setWindowTitle( "10" ) } ) oButton[11]:Connect( "clicked()", { || oWnd:setWindowTitle( "11" ) } ) oButton[12]:Connect( "clicked()", { || oWnd:setWindowTitle( "12" ) } ) oButton[13]:Connect( "clicked()", { || oWnd:setWindowTitle( "13" ) } )

oWnd:show() QApplication():exec()

RETURN

QStatusBar - Status BarThe following example shows how to create and modify the status bar, at the bottom ofthe window.

PROCEDURE Main()

LOCAL oWnd LOCAL oSBar

oWnd := QMainWindow() oWnd:show()

oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 300, 200 )

oSBar := QStatusBar( oWnd ) oWnd:setStatusBar( oSBar )

oSBar:showMessage( "Harbour-QT Statusbar Ready!" )

QApplication():exec()

RETURN

QStatusBar - Status Bar and time clockThe following example shows how to show a clock on the status bar, at the bottom of thewindow.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

46 de 195 13/02/2013 18:56

Page 47: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oSBar LOCAL oClock

oWnd := QMainWindow()

oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 300, 200 )

oClock := QTimer() oClock:Connect( "timeout()", { || oSBar:showMessage( Time() ) } ) oClock:start( 1000 )

oSBar := QStatusBar( oWnd ) oWnd:setStatusBar( oSBar )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

QStatusBar - Status Bar Ping PongThe following example shows how create a status bar with a ping pong effect. The statusbar goes to left and right.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

47 de 195 13/02/2013 18:56

Page 48: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oClock LOCAL oSBar LOCAL nSpaces, nInc

oWnd := QMainWindow()

oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 300, 200 )

nSpaces := 1 nInc := 1

oClock := QTimer() oClock:Connect( "timeout()", { || pingpong( oSBar, @nSpaces, @nInc ) } ) oClock:start( 25 )

oSBar := QStatusBar( oWnd ) oSBar:move( 100, 1 )

oWnd:setStatusBar( oSBar )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE pingpong( oSb, nSp, nI )

LOCAL cString

cString := Space( nSp ) + "Hello" oSb:showMessage( cString ) nSp += nI

IF nSp == 40 nI =- 1 ENDIF

IF nSp == 1 nI := 1 ENDIF

RETURN

QStatusBar - Colored Status BarThe following example shows how to create and modify a colored status bar, at thebottom of the window.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

48 de 195 13/02/2013 18:56

Page 49: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oSBar

oWnd := QMainWindow()

oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 300, 200 )

oSBar := QStatusBar( oWnd ) oWnd:setStatusBar( oSBar )

oSBar:showMessage( "This is a colored Statusbar" ) oSBar:setStyleSheet( "background-color : yellow; color : red;" )

oWnd:show() QApplication():exec()

RETURN

QStatusBar - Status Bar with timeoutThe following example shows how to display a status bar for "n" milliseconds and then itdesappears. The value of timeout is expressed in milliseconds.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

49 de 195 13/02/2013 18:56

Page 50: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oSBar

oWnd := QMainWindow() oWnd:show()

oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 300, 200 )

oSBar := QStatusBar( oWnd ) oWnd:setStatusBar( oSBar )

oSBar:showMessage( "Message displayed for 5 seconds..." , 5000 )

QApplication():exec()

RETURN

QStatusBar - Multiple Status BarThe following example shows how to create a status bar composed by several widgets.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

50 de 195 13/02/2013 18:56

Page 51: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oStatusBar LOCAL oText1, oText2, oText3

oWnd := QMainWindow() oWnd:show()

oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 600, 200 )

oText1 := QLabel() oText1:setText( "Status Bar 1" ) oText1:setStyleSheet( "background-color : #BBBBFF;" )

oText2 := QLabel() oText2:setText( "Date: " + DToC( Date() ) )

oText3 := QLabel() oText3:setText( "Time: " + Time() ) oText3:setStyleSheet( "color : red;" )

oStatusBar := QStatusBar( oWnd ) oStatusBar:addWidget( oText1, 0 ) oStatusBar:addWidget( oText2, 0 ) oStatusBar:addWidget( oText3, 0 )

oWnd:setStatusBar( oStatusBar )

QApplication():exec()

RETURN

QStatusBar - Status Bar and Progress BarThe following example shows how to add a progress bar to the status bar.

PROCEDURE Main()

LOCAL oWnd, oStatusBar, oClock, oText, oBar

oWnd := QMainWindow()

oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 500, 200 )

oText := QLabel() oText:setText( Time() )

oBar := QProgressBar() oBar:setRange( 1, 100 ) oBar:setValue( 1 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

51 de 195 13/02/2013 18:56

Page 52: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oClock := QTimer() oClock:Connect( "timeout()", {|| updateStatusBar( oText, oBar ) } ) oClock:start( 1000 )

oStatusBar := QStatusBar( oWnd ) oStatusBar:addWidget( oText, 0 ) oStatusBar:addWidget( oBar, 1 )

oWnd:setStatusBar( oStatusBar ) oWnd:show()

QApplication():exec() oClock:stop()

RETURN

PROCEDURE updateStatusBar( oT, oB )

oT:setText( Time() ) oB:setValue( oB:value() + 1 )

RETURN

QStatusBar - Comboboxes in the Status BarThe following example shows how to add comboboxes to the status bar.

PROCEDURE Main()

LOCAL oWnd, oStatusBar LOCAL oCombo1, oCombo2

oWnd := QMainWindow() oWnd:show()

oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 600, 200 )

oCombo1 := QComboBox() oCombo1:addItem( "Small" ) oCombo1:addItem( "Medium" ) oCombo1:addItem( "Large" )

oCombo2 := QComboBox() oCombo2:addItem( "COM1" ) oCombo2:addItem( "COM2" ) oCombo2:addItem( "COM3" ) oCombo2:addItem( "COM4" )

oStatusBar := QStatusBar( oWnd ) oStatusBar:addWidget( oCombo1, 0 ) oStatusBar:addWidget( oCombo2, 0 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

52 de 195 13/02/2013 18:56

Page 53: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:setStatusBar( oStatusBar )

QApplication():exec()

RETURN

QCursor - Cursor ManagingThe following example shows how to modify the cursor of the mouse, over widgets.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oCursor

oCursor := QCursor() oCursor:setShape( Qt_WaitCursor )

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oWnd:SetCursor( oCursor ) oWnd:show() QApplication():exec()

RETURN

QTabWidget - TAB ControlThe following example shows how to create three Tab Widget.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

53 de 195 13/02/2013 18:56

Page 54: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oBar LOCAL oComputer, oMonitor, oPrinter

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 500, 300 )

oComputer := QWidget() oMonitor := QWidget() oPrinter := QWidget()

oBar := QTabWidget( oWnd ) oBar:resize( 400, 200 ) oBar:move( 50, 50 ) oBar:addTab( oComputer, "Computers" ) oBar:addTab( oMonitor, "Monitors" ) oBar:addTab( oPrinter, "Printers" )

oWnd:show() QApplication():exec()

RETURN

QTabWidget - TAB Controls in a TAB ControlThe following example shows how to create many Tab Widgets in three Tab Widgets.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

54 de 195 13/02/2013 18:56

Page 55: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oBar, oBar2, oBar3, oBar4 LOCAL oComputer, oMonitor, oPrinter LOCAL oAmd, oIntel LOCAL oCrt, oLcd LOCAL oLaser, oInk, oDotmatrix, oThermal

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 500, 300 )

oComputer := QWidget() oMonitor := QWidget() oPrinter := QWidget()

oBar := QTabWidget( oWnd ) oBar:resize( 400, 200 ) oBar:move( 50, 50 ) oBar:addTab( oComputer, "Computers" ) oBar:addTab( oMonitor, "Monitors" ) oBar:addTab( oPrinter, "Printers" )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

55 de 195 13/02/2013 18:56

Page 56: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oAmd := QWidget() oIntel := QWidget() oBar2 := QTabWidget( oComputer ) oBar2:resize( 200, 100 ) oBar2:move( 50, 50 ) oBar2:addTab( oAmd, "Cpu Amd" ) oBar2:addTab( oIntel, "Cpu Intel" )

oCrt := QWidget() oLcd := QWidget() oBar3 := QTabWidget( oMonitor ) oBar3:resize( 200, 100 ) oBar3:move( 50, 50 ) oBar3:addTab( oCrt, "Monitor CRT" ) oBar3:addTab( oLcd, "Monitor LCD" )

oLaser := QWidget() oInk := QWidget() oDotmatrix := QWidget() oThermal := QWidget() oBar4 := QTabWidget( oPrinter ) oBar4:resize( 380, 100 ) oBar4:move( 10, 50 ) oBar4:addTab( oLaser, "Laser Printer" ) oBar4:addTab( oInk, "Inkjet Printer" ) oBar4:addTab( oDotmatrix, "Dot-matrix Printer" ) oBar4:addTab( oThermal, "Thermal Printer" )

oWnd:show() QApplication():exec()

RETURN

QTimer - TimerThe following example shows a clock every 1 second, thank to QTimer class. The time ofrefresh can be adjusted by the start(x) property.

PROCEDURE Main()

LOCAL oWnd LOCAL oClock LOCAL oText

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 250, 150 )

oText := QLabel( oWnd ) oText:setText( "clocking..." ) oText:move( 100, 100 )

oClock := QTimer() oClock:Connect( "timeout()", { || print_clock( oText ) } )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

56 de 195 13/02/2013 18:56

Page 57: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oClock:start( 1000 )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE print_clock( oT )

oT:setText( Time() )

RETURN

QTimer - Timer with controlsThe following example shows a clock every a second, thank to QTimer class. The time ofrefresh can be adjusted by the start(x) property. If the Start button is pressed, the time isupdated every a second. If the Stop button is pressed, the time stops.

PROCEDURE Main()

LOCAL oWnd LOCAL oButtonStart, oButtonStop

LOCAL oClock, oText

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oText := QLabel( oWnd ) oText:setText( "clocking..." ) oText:move( 50, 50 ) oText:resize( 200, 100 )

oClock := QTimer() oClock:Connect( "timeout()", { || oText:setText( Time() ) } )

oButtonStart := QPushButton( oWnd ) oButtonStart:move( 150, 50 ) oButtonStart:setText( "Start" ) oButtonStart:connect( "pressed()", { || oClock:start( 1000 ) } )

oButtonStop := QPushButton( oWnd ) oButtonStop:move( 150, 100 ) oButtonStop:setText( "Stop" ) oButtonStop:connect( "pressed()", { || oClock:stop() } )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

57 de 195 13/02/2013 18:56

Page 58: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QTimer - Timer in the Window TitleThe following example shows a clock on the Title bar of a window.

PROCEDURE Main()

LOCAL oWnd LOCAL oClock

oWnd := QMainWindow() oWnd:resize( 250, 150 )

oClock := QTimer() oClock:Connect( "timeout()", { || oWnd:setWindowTitle( Time() ) } ) oClock:start( 1000 )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

QTimer - Scrolling textThe following example shows how to create a scrolling text, using qTimer class. Thescrolling text is a text in a label. Every 100 milliseconds, this string is updated, byremoving the first character and putting it at the end of the string. This gives the illusionof the scrolling.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

58 de 195 13/02/2013 18:56

Page 59: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oText, oClock

oWnd := QMainWindow() oWnd:setWindowTitle( "Scrolling text" ) oWnd:resize( 400, 200 )

oText := QLabel( oWnd ) oText:setText( "This simple program shows how to scroll a text in a Label. " ) oText:resize( 300, 40 ) oText:move( 50, 100 ) oText:setStyleSheet( "background-color: #CCCCCC; border: 1px solid #333333;" )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

59 de 195 13/02/2013 18:56

Page 60: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oClock := QTimer() oClock:Connect( "timeout()", { || scorrimento( oText ) } ) oClock:start( 100 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE scorrimento( o )

LOCAL cSt

cSt := o:Text() cSt := SubStr( cSt, 2 ) + Left( cSt, 1 ) o:setText( cSt )

RETURN

QTimer - CountdownThe following example shows how to create a program for a countdown. The time startsfrom 60 seconds. Pressing the "start" button, the countdown starts. You can press the"start" button anytime.

PROCEDURE Main()

LOCAL oWnd LOCAL oButtonStart LOCAL oDisplay, oClock

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oDisplay := QLCDNumber( oWnd ) oDisplay:resize( 100, 50 ) oDisplay:move( 150, 20 ) oDisplay:display( 60 )

oClock := QTimer() oClock:Connect( "timeout()", { || print_clock( oDisplay,oClock ) } )

oButtonStart := QPushButton( oWnd ) oButtonStart:move( 150, 100 ) oButtonStart:resize( 100, 50 ) oButtonStart:setText( "Start" ) oButtonStart:connect( "pressed()", { || start( oDisplay,oClock ) } )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE start( oD, oC )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

60 de 195 13/02/2013 18:56

Page 61: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oD:display( 60 ) oC:start( 1000 )

RETURN

PROCEDURE print_clock( oD, oC )

LOCAL s

s := oD:value() s := s - 1 oD:display( s ) IF s == 0 oC:stop() end IF

RETURN

QSS - QSS Style SheetThe following example shows how we can use CSS to change any property of objects.

PROCEDURE Main()

LOCAL oWnd, oButton1

oWnd := QMainWindow() oWnd:setWindowTitle( "Prova dei pulsanti" ) oWnd:resize( 300, 200 )

oButton1 := QPushButton( oWnd ) oButton1:setText( "Quit" ) oButton1:move( 50, 50 ) oButton1:Connect( "clicked()", { || QApplication():quit() } ) oButton1:setStyleSheet( "background-color: yellow; border: 2px solid #FF0000;" )

oWnd:show() QApplication():exec()

RETURN

QSS - Gradient (linear: top to bottom)The following example shows how we can use CSS to change any property of objects. Inparticular it shows the creation of a linear gradient.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

61 de 195 13/02/2013 18:56

Page 62: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oLabel

oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oLabel := QLabel( oWnd ) oLabel:setText( "Gradient" ) oLabel:move( 50, 50 ) oLabel:resize( 100, 100 ) oLabel:setStyleSheet( "background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FF0000, stop:1 #FFFF00);

oWnd:show() QApplication():exec()

RETURN

QSS - Gradient (linear: left to right)The following example shows how we can use CSS to change any property of objects. Inparticular it shows the creation of a linear gradient.

PROCEDURE Main()

LOCAL oWnd, oLabel

oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oLabel := QLabel( oWnd )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

62 de 195 13/02/2013 18:56

Page 63: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oLabel:setText( "Gradient" ) oLabel:move( 50, 50 ) oLabel:resize( 100, 100 ) oLabel:setStyleSheet( "background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0,stop:0 #0000FF, stop:1 #FFFFFF);

oWnd:show() QApplication():exec()

RETURN

QSS - Gradient (linear: left-top to right-bottom)The following example shows how we can use CSS to change any property of objects. Inparticular it shows the creation of a linear gradient.

PROCEDURE Main()

LOCAL oWnd, oLabel

oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oLabel := QLabel( oWnd ) oLabel:setText( "Gradient" ) oLabel:move( 50, 50 ) oLabel:resize( 100, 100 ) oLabel:setStyleSheet( "background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1,stop:0 #00FF00, stop:1 #004400);

oWnd:show() QApplication():exec()

RETURN

QSS - Radial GradientThe following example shows how we can use CSS to change any property of objects. Inparticular it shows the creation of a radial gradient.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

63 de 195 13/02/2013 18:56

Page 64: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oLabel

oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oLabel := QPushButton( oWnd ) oLabel:setText( "Gradient" ) oLabel:move( 50, 50 ) oLabel:resize( 100, 100 ) oLabel:setStyleSheet( "color: #333; border: 2px solid #555; border-radius: 11px; padding: 5px; background: qradi

oWnd:show() QApplication():exec()

RETURN

QSS - Colored QLCDNumberThe following example shows a colored QLCDNumber by QSS.

PROCEDURE Main()

LOCAL oWnd LOCAL oLcd

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

64 de 195 13/02/2013 18:56

Page 65: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oLcd := QLCDNumber( oWnd ) oLcd:move( 50, 50 ) oLcd:resize( 300, 100 ) oLcd:setNumDigits ( 8 ) oLcd:setStyleSheet( "color: #FF0000;" ) oLcd:display ( "43'" )

oWnd:show() QApplication():exec()

RETURN

QMenu - MenuThe following example shows the usage of menu. Every item can be connected to anyfunction or UDF.

PROCEDURE Main()

LOCAL oWnd, oWnd2, oWnd3 LOCAL oMenuBar, oMenu1, oItemIns, oItemMod

// ----------Window----------- oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Giovanni" )

oWnd2 := QMainWindow() oWnd2:SetFixedSize( 640, 480 ) oWnd2:setWindowTitle( "Insert" )

oWnd3 := QMainWindow() oWnd3:SetFixedSize( 640, 480 ) oWnd3:setWindowTitle( "Edit" )

// ----------Menu----------- oMenuBar := QMenuBar( oWnd ) oMenuBar:resize( 300, 30 )

oMenu1 := QMenu() oMenu1:setTitle( "File" )

oItemIns := QAction( oMenu1 ) oItemIns:setText( "Insert" ) oItemIns:connect( "triggered(bool)", { || oWnd2:Show() } )

oItemMod := QAction( oMenu1 ) oItemMod:setText( "Edit" ) oItemMod:connect( "triggered(bool)", { || oWnd3:Show() } )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

65 de 195 13/02/2013 18:56

Page 66: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oMenu1:addAction( oItemIns ) oMenu1:addAction( oItemMod )

oMenuBar:addMenu( oMenu1 )

oWnd:Show() QApplication():exec()

RETURN

QMenu - Menu with separatorsThe following example shows the usage of menu. An item can separated from the otherby a line separator. Every item can be connected to any function or UDF.

PROCEDURE Main()

LOCAL oWnd, oWnd2, oWnd3 LOCAL oMenuBar, oMenu1, oItemIns, oItemMod

// ----------Window----------- oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Giovanni" )

oWnd2 := QMainWindow() oWnd2:SetFixedSize( 640, 480 ) oWnd2:setWindowTitle( "Insert" )

oWnd3 := QMainWindow() oWnd3:SetFixedSize( 640, 480 ) oWnd3:setWindowTitle( "Edit" )

// ----------Menu----------- oMenuBar := QMenuBar( oWnd ) oMenuBar:resize( 300, 30 )

oMenu1 := QMenu() oMenu1:setTitle( "File" )

oItemIns := QAction( oMenu1 ) oItemIns:setText( "Insert" ) oItemIns:connect( "triggered(bool)", { || oWnd2:Show() } )

oItemMod := QAction( oMenu1 ) oItemMod:setText( "Edit" ) oItemMod:connect( "triggered(bool)", { || oWnd3:Show() } )

oMenu1:addAction( oItemIns ) oMenu1:addSeparator() oMenu1:addAction( oItemMod )

oMenuBar:addMenu( oMenu1 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

66 de 195 13/02/2013 18:56

Page 67: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:Show() QApplication():exec()

RETURN

QMenu - Menu and sub-menuThe following example shows the usage of menu and sub-menu. The sub-menu is also amenu.

PROCEDURE Main()

LOCAL oWnd LOCAL oMenuBar, oMenu1, oMenu2 LOCAL oItemMod LOCAL oItemInsImage, oItemInsTable, oItemInsPage

// ----------Window----------- oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Giovanni" )

// ----------Menu----------- oMenuBar := QMenuBar( oWnd ) oMenuBar:resize( 300, 30 )

oMenu1 := QMenu() oMenu1:setTitle( "File" )

oMenu2 := QMenu() oMenu2:setTitle( "Insert" )

oItemInsImage := QAction( oMenu2 ) oItemInsImage:setText( "Insert Image" ) oItemInsImage:connect( "triggered(bool)", { || image() } ) oMenu2:addAction( oItemInsImage )

oItemInsTable := QAction( oMenu2 ) oItemInsTable:setText( "Insert Table" ) oItemInsTable:connect( "triggered(bool)", { || table() } ) oMenu2:addAction( oItemInsTable )

oItemInsPage := QAction( oMenu2 ) oItemInsPage:setText( "Insert Table" ) oItemInsPage:connect( "triggered(bool)", { || page() } ) oMenu2:addAction( oItemInsPage )

oMenu1:addMenu( oMenu2 )

oItemMod := QAction( oMenu1 ) oItemMod:setText( "Edit" ) oItemMod:connect( "triggered(bool)", { || edit() } )

oMenu1:addAction( oItemMod )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

67 de 195 13/02/2013 18:56

Page 68: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oMenuBar:addMenu( oMenu1 )

oWnd:Show() QApplication():exec()

RETURN

PROCEDURE edit()

// Type your code here

RETURN

PROCEDURE image()

// Type your code here

RETURN

PROCEDURE table()

// Type your code here

RETURN

PROCEDURE page()

// Type your code here

RETURN

QMenu - Colored MenuThe following example shows the usage of a colored menu. Every item can beconnected to any function or UDF.

#define cSTYLE "background-color : yellow; color : red; selection-color: white; selection-background-color: blue;"

PROCEDURE Main()

LOCAL oWnd LOCAL oMenuBar, oMenu1, oItemIns, oItemMod

// ----------Window----------- oWnd := QMainWindow() oWnd:SetFixedSize( 300, 200 ) oWnd:setWindowTitle( "Giovanni" )

// ----------Menu----------- oMenuBar := QMenuBar( oWnd ) oMenuBar:resize( 300, 30 )

oMenu1 := QMenu() oMenu1:setTitle( "File" )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

68 de 195 13/02/2013 18:56

Page 69: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oMenu1:setStyleSheet( cSTYLE )

oItemIns := QAction( oMenu1 ) oItemIns:setText( "Insert" ) oItemIns:connect( "triggered(bool)", { || insert() } )

oItemMod := QAction( oMenu1 ) oItemMod:setText( "Edit" ) oItemMod:connect( "triggered(bool)", { || edit() } )

oMenu1:addAction( oItemIns ) oMenu1:addAction( oItemMod )

oMenuBar:addMenu( oMenu1 )

oWnd:Show() QApplication():exec()

RETURN

PROCEDURE insert()

// Type your code here

RETURN

PROCEDURE edit()

// Type your code here

RETURN

QMenu - A complex MenuThe following example shows how to create a complex menu.

PROCEDURE Main()

LOCAL oWnd LOCAL oMenuBar LOCAL oMenu1, oMenu2, oMenu3 LOCAL oSubMenu11, oSubMenu12, oSubMenu21, oSubMenu31 LOCAL oSubMenu113 LOCAL oItem111, oItem112 LOCAL oItem1131, oItem1132 LOCAL oItem211, oItem212

// ---------- Window ----------- oWnd := QMainWindow()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

69 de 195 13/02/2013 18:56

Page 70: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:reSize( 640, 480 ) oWnd:setWindowTitle( "Giovanni" )

// ---------- Menu ----------- oMenuBar := QMenuBar( oWnd ) oMenuBar:resize( 640, 30 )

// ---------- Menu 1 ---------- oMenu1 := QMenu() oMenu1:setTitle( "Menu_1" ) // ---------- SubMenu 11 ---------- oSubMenu11 := QMenu() oSubMenu11:setTitle( "SubMenu_11" ) // --------- Items --------- oItem111 := QAction( oSubMenu11 ) oItem111:setText( "Item_111" ) oItem111:connect( "triggered(bool)", { || Item_111() } ) oSubMenu11:addAction( oItem111 ) oItem112 := QAction( oSubMenu11 ) oItem112:setText( "Item_112" ) oItem112:connect( "triggered(bool)", { || Item_112() } ) oSubMenu11:addAction( oItem112 ) oSubMenu11:addSeparator() //==================== // ---------- SubMenu 113 ---------- oSubMenu113 := QMenu() oSubMenu113:setTitle( "SubMenu_113" ) // --------- Items --------- oItem1131 := QAction( oSubMenu113 ) oItem1131:setText( "Item_1131" ) oItem1131:connect( "triggered(bool)", { ||Item_1131() } ) oSubMenu113:addAction( oItem1131 ) oItem1132 := QAction( oSubMenu113 ) oItem1132:setText( "Item_1132" ) oItem1132:connect( "triggered(bool)", { ||Item_1132() } ) oSubMenu113:addAction( oItem1132 ) oSubMenu11:addMenu( oSubMenu113 ) oMenu1:addMenu( oSubMenu11 ) oMenu1:addSeparator() //==================== // ---------- SubMenu 12 ---------- oSubMenu12 := QAction( oMenu1 ) oSubMenu12:setText( "SubMenu_12" ) oSubMenu12:connect( "triggered(bool)", { || SubMenu_12() } ) oMenu1:addAction( oSubMenu12 ) oMenuBar:addMenu( oMenu1 ) // ---------- Menu 2 ---------- oMenu2 := QMenu() oMenu2:setTitle( "Menu_2" ) // ---------- SubMenu 21 ---------- oSubMenu21 := QMenu() oSubMenu21:setTitle( "SubMenu_21" ) // --------- Items --------- oItem211 := QAction( oSubMenu21 ) oItem211:setText( "Item_211" ) oItem211:connect( "triggered(bool)", { || Item_211() } ) oSubMenu21:addAction( oItem211 ) oItem212 := QAction( oSubMenu21 ) oItem212:setText( "Item_212" ) oItem212:connect( "triggered(bool)", { || Item_212() } ) oSubMenu21:addAction( oItem212 ) oMenu2:addMenu( oSubMenu21 ) oMenuBar:addMenu( oMenu2 ) // ---------- Menu 3 ---------- oMenu3 := QMenu() oMenu3:setTitle( "Menu_3" ) // ---------- SubMenu 31 ---------- oSubMenu31 := QAction( oMenu3 ) oSubMenu31:setText( "SubMenu_31" ) oSubMenu31:connect( "triggered(bool)", { || SubMenu_31() } ) oMenu3:addAction( oSubMenu31 ) oMenuBar:addMenu( oMenu3 )

oWnd:Show() QApplication():exec()

RETURN

PROCEDURE Item_111()

// Type your code here

RETURN

PROCEDURE Item_112()

// Type your code here

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

70 de 195 13/02/2013 18:56

Page 71: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

RETURN

PROCEDURE Item_1131()

// Type your code here

RETURN

PROCEDURE Item_1132()

// Type your code here

RETURN

PROCEDURE SubMenu_12()

// Type your code here

RETURN

PROCEDURE Item_211()

// Type your code here

RETURN

PROCEDURE Item_212()

// Type your code here

RETURN

PROCEDURE SubMenu_31()

// Type your code here

RETURN

UI - UI file created with QT Creator

At the moment the QUiLoader() class is notpresent.

The following example shows how to draw a window or a complete set of widget, from a UI filecreated with QT Creator program.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

71 de 195 13/02/2013 18:56

Page 72: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oUi, oFile

oFile := QFile( "sample.ui" ) oFile:open( 1 )

oUi := QUiLoader() oWnd := oUi:load( oFile ) oFile:close()

oWnd:show() QApplication():exec()

RETURN

UI - A fully functional example with UI fileThe following example uses a file .UI created with QT Creator program. Pressing thebutton, the title changes.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

72 de 195 13/02/2013 18:56

Page 73: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd

oWnd := hbqtui_form() oWnd:setWindowTitle( "Old Title" ) oWnd:q_pushButton:Connect( "clicked()", { ||oWnd:setWindowTitle( "Changed" ) } )

oWnd:show() QApplication():exec()

RETURN

This is the form.ui file, created with QT Creator

<?xml version="1.0" encoding="UTF-8"?><ui version="4.0"> <class>Form</class> <widget class="QWidget" name="Form"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>325</width> <height>129</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <widget class="QPushButton" name="pushButton"> <property name="geometry"> <rect> <x>50</x> <y>50</y> <width>211</width> <height>23</height> </rect> </property> <property name="text"> <string>Change Title Bar</string> </property> </widget> </widget> <resources/> <connections/></ui>

To work correctly, the programmer must remember the following rules:

You must create the file "form.ui" (or other name) with QT Creator1.You must include the "form.ui" file in the compilation (directly or in the file .HBP)2.To refer to children of the widget, you must "rename" the objects with "q_" at thebeginning of the line. For example: q_pushButton

3.

The "form.ui" file is not necessary for the execution of the program. It's compiled inthe .exe file

4.

If the name of the .UI file is "form.ui", then you must call the hbqtui_form() function.If the name of the .UI file is "example.ui", then you must call the hbqtui_example()function.

5.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

73 de 195 13/02/2013 18:56

Page 74: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QTableWidget - Simple tableThe following example shows how to create a small table, with 2 rows and 2 columns.

PROCEDURE Main()

LOCAL oWnd LOCAL oTable LOCAL oCell, oLabel

oWnd := QMainWindow() oWnd:resize( 400, 300 ) oWnd:setWindowTitle( "Giovanni" ) //------------Table-------------- oTable := QTableWidget( oWnd ) oTable:move( 50, 50 ) oTable:resize( 300, 200 ) oTable:setRowCount( 2 ) oTable:setColumnCount( 2 ) oTable:setColumnWidth( 0, 70 ) oTable:setColumnWidth( 1, 90 ) //------------Fill Table-------------- oCell := QTableWidgetItem() oCell:setText( "1986" ) oTable:setItem( 0, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( "123" ) oTable:setItem( 0, 1, oCell )

oCell := QTableWidgetItem() oCell:setText( "1998" ) oTable:setItem( 1, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( "177" ) oTable:setItem( 1, 1, oCell )

oLabel := QStringList() oLabel:append( "Year" ) oLabel:append( "Number of Dogs" ) oTable:setHorizontalHeaderLabels( oLabel )

oWnd:show() QApplication():exec()

RETURN

QTableWidget - Arithmetic tables

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

74 de 195 13/02/2013 18:56

Page 75: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

The following example shows how to create an Arithmetic table, with 100 rows and 4columns. The first column contains the number, the second column contains the squareof the number, the third column contains the square root of the number and the fourthcolumn contains the cube of the number. The numbers are generated by a loop.

PROCEDURE Main()

LOCAL oWnd LOCAL oCell, oLabel LOCAL k LOCAL oTable

oWnd := QMainWindow() oWnd:resize( 600, 600 ) oWnd:setWindowTitle( "Giovanni" )

//------------Table-------------- oTable := QTableWidget( oWnd ) oTable:move( 10, 10 ) oTable:resize( 580, 580 ) oTable:setRowCount( 100 ) oTable:setColumnCount( 4 ) oTable:setColumnWidth( 0, 70 ) oTable:setColumnWidth( 1, 90 )

//------------Fill Table-------------- for k := 1 TO 100 oCell := QTableWidgetItem()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

75 de 195 13/02/2013 18:56

Page 76: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oCell:setText( AllTrim( Str(k ) ) ) oTable:setItem( k - 1, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ^ 2 ) ) ) oTable:setItem( k - 1, 1, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(Sqrt(k ) ) ) ) oTable:setItem( k - 1, 2, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ^ 3 ) ) ) oTable:setItem( k - 1, 3, oCell ) next k

oLabel := QStringList() oLabel:append( "N." ) oLabel:append( "Square" ) oLabel:append( "Square root" ) oLabel:append( "Cube" ) oTable:setHorizontalHeaderLabels( oLabel )

oWnd:show() QApplication():exec()

RETURN

QTableWidget - Colored CellsThe following example shows how to create a small table, with 2 rows and 2 columns.The cells are colored.

PROCEDURE Main()

LOCAL oWnd LOCAL oTable LOCAL oCell, oLabel

oWnd := QMainWindow() oWnd:resize( 400, 300 ) oWnd:setWindowTitle( "Giovanni" )

//------------Table-------------- oTable := QTableWidget( oWnd ) oTable:move( 50, 50 ) oTable:resize( 300, 200 ) oTable:setRowCount( 2 ) oTable:setColumnCount( 2 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

76 de 195 13/02/2013 18:56

Page 77: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oTable:setColumnWidth( 0, 70 ) oTable:setColumnWidth( 1, 90 ) //------------Fill Table-------------- oCell := QTableWidgetItem() oCell:setText( "1986" ) oCell:setForeground( QBrush( QColor(255,0,0 ) ) ) oCell:setBackground( QBrush( QColor(255,255,100 ) ) ) oTable:setItem( 0, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( "123" ) oCell:setForeground( QBrush( QColor(0,150,0 ) ) ) oTable:setItem( 0, 1, oCell )

oCell := QTableWidgetItem() oCell:setText( "1998" ) oCell:setForeground( QBrush( QColor(255,255,0 ) ) ) oCell:setBackground( QBrush( QColor(0,0,150 ) ) ) oTable:setItem( 1, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( "177" ) oCell:setForeground( QBrush( QColor(255,0,0 ) ) ) oTable:setItem( 1, 1, oCell )

oLabel := QStringList() oLabel:append( "Year" ) oLabel:append( "Number of Dogs" )

oTable:setHorizontalHeaderLabels( oLabel )

oWnd:show() QApplication():exec()

RETURN

QTableWidget - Arithmetic tables (colored columns)The following example shows how to create an Arithmetic table, with 100 rows and 4columns. The first column contains the number, the second column contains the squareof the number, the third column contains the square root of the number and the fourthcolumn contains the cube of the number. The numbers are generated by a loop. Thecolumns are colored.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

77 de 195 13/02/2013 18:56

Page 78: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oCell, oLabel LOCAL k LOCAL oTable

oWnd := QMainWindow() oWnd:resize( 600, 600 ) oWnd:setWindowTitle( "Giovanni" )

//------------Table-------------- oTable := QTableWidget( oWnd ) oTable:move( 10, 10 ) oTable:resize( 580, 580 ) oTable:setRowCount( 100 ) oTable:setColumnCount( 4 ) oTable:setColumnWidth( 0, 70 ) oTable:setColumnWidth( 1, 90 )

//------------Fill Table-------------- for k := 1 TO 100 oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ) ) ) oCell:setForeground( QBrush( QColor(255,0,0 ) ) ) oCell:setBackground( QBrush( QColor(255,255,100 ) ) ) oTable:setItem( k - 1, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ^ 2 ) ) ) oCell:setForeground( QBrush( QColor(255,255,255 ) ) )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

78 de 195 13/02/2013 18:56

Page 79: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oCell:setBackground( QBrush( QColor(0,0,250 ) ) ) oTable:setItem( k - 1, 1, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(Sqrt(k ) ) ) ) oCell:setForeground( QBrush( QColor(255,255,255 ) ) ) oCell:setBackground( QBrush( QColor(200,50,200 ) ) ) oTable:setItem( k - 1, 2, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ^ 3 ) ) ) oCell:setForeground( QBrush( QColor(0,100,0 ) ) ) oCell:setBackground( QBrush( QColor(200,255,200 ) ) ) oTable:setItem( k - 1, 3, oCell ) next k

oLabel := QStringList() oLabel:append( "N." ) oLabel:append( "Square" ) oLabel:append( "Square root" ) oLabel:append( "Cube" ) oTable:setHorizontalHeaderLabels( oLabel )

oWnd:show() QApplication():exec()

RETURN

QTableWidget - Arithmetic tables (conditional coloring of rows)The following example shows how to create an Arithmetic table, with 100 rows and 4columns. The first column contains the number, the second column contains the squareof the number, the third column contains the square root of the number and the fourthcolumn contains the cube of the number. The numbers are generated by a loop. Therows are colored following a condition (even and odd).

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

79 de 195 13/02/2013 18:56

Page 80: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oCell, oLabel LOCAL k LOCAL oBrushForeground, oBrushBackground LOCAL oTable

oWnd := QMainWindow() oWnd:resize( 600, 600 ) oWnd:setWindowTitle( "Giovanni" )

//------------Table-------------- oTable := QTableWidget( oWnd ) oTable:move( 10, 10 ) oTable:resize( 580, 580 ) oTable:setRowCount( 100 ) oTable:setColumnCount( 4 ) oTable:setColumnWidth( 0, 70 ) oTable:setColumnWidth( 1, 90 )

//------------Fill Table--------------

for k := 1 TO 100

IF k % 2 == 0 oBrushForeground := QBrush( QColor( 0,0,200 ) ) oBrushBackground := QBrush( QColor( 220,255,220 ) ) ELSE oBrushForeground := QBrush( QColor( 0,0,200 ) ) oBrushBackground := QBrush( QColor( 220,220,255 ) )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

80 de 195 13/02/2013 18:56

Page 81: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

ENDIF

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ) ) ) oCell:setForeground( oBrushForeground ) oCell:setBackground( oBrushBackground ) oTable:setItem( k - 1, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ^ 2 ) ) ) oCell:setForeground( oBrushForeground ) oCell:setBackground( oBrushBackground ) oTable:setItem( k - 1, 1, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(Sqrt(k ) ) ) ) oCell:setForeground( oBrushForeground ) oCell:setBackground( oBrushBackground ) oTable:setItem( k - 1, 2, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ^ 3 ) ) ) oCell:setForeground( oBrushForeground ) oCell:setBackground( oBrushBackground ) oTable:setItem( k - 1, 3, oCell ) next k

oLabel := QStringList() oLabel:append( "N." ) oLabel:append( "Square" ) oLabel:append( "Square root" ) oLabel:append( "Cube" ) oTable:setHorizontalHeaderLabels( oLabel )

oWnd:show() QApplication():exec()

RETURN

QTableWidget - Sorting columsThe following example shows how to sort the colums in a table, by pressing therespective buttons.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

81 de 195 13/02/2013 18:56

Page 82: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oTable LOCAL oCell, oLabel LOCAL k LOCAL oButton1, oButton2

oWnd := QMainWindow() oWnd:resize( 400, 600 ) oWnd:setWindowTitle( "Giovanni" ) //------------Table-------------- oTable := QTableWidget( oWnd ) oTable:move( 50, 50 ) oTable:resize( 300, 500 ) oTable:setRowCount( 14 ) oTable:setColumnCount( 2 ) oTable:setColumnWidth( 0, 100 ) oTable:setColumnWidth( 1, 100 )

//------------Headers-------------- oLabel := QStringList() oLabel:append( "Random 1" ) oLabel:append( "Random 2" ) oTable:setHorizontalHeaderLabels( oLabel )

//------------Fill Table-------------- for k := 0 TO 13 oCell := QTableWidgetItem() oCell:setText( StrZero( hb_RandomInt (1,1000 ),4 ) ) oTable:setItem( k, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( StrZero( hb_RandomInt (1,100 ),3 ) ) oTable:setItem( k, 1, oCell ) next k

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

82 de 195 13/02/2013 18:56

Page 83: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

//------------Buttons-------------- oButton1 := QPushButton( oWnd ) oButton1:setText( "Sort" ) oButton1:move( 70, 10 ) oButton1:Connect( "clicked()", { || oTable:sortItems ( 0 ) } )

oButton2 := QPushButton( oWnd ) oButton2:setText( "Sort" ) oButton2:move( 180, 10 ) oButton2:Connect( "clicked()", { || oTable:sortItems ( 1 ) } )

oWnd:show() QApplication():exec()

RETURN

QTableWidget - Alternate colors of rowsThe following example shows how to color alternating rows, usingsetAlternatingRowColors function.

PROCEDURE Main()

LOCAL oWnd LOCAL oCell, oLabel LOCAL k LOCAL oTable

oWnd := QMainWindow() oWnd:resize( 600, 600 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

83 de 195 13/02/2013 18:56

Page 84: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:setWindowTitle( "Giovanni" )

//------------Table-------------- oTable := QTableWidget( oWnd ) oTable:move( 10, 10 ) oTable:resize( 580, 580 ) oTable:setRowCount( 100 ) oTable:setColumnCount( 2 ) oTable:setColumnWidth( 0, 70 ) oTable:setColumnWidth( 1, 90 ) oTable:setAlternatingRowColors( .T. )

//------------Fill Table-------------- for k := 1 TO 100 oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ) ) ) oTable:setItem( k - 1, 0, oCell )

oCell := QTableWidgetItem() oCell:setText( AllTrim( Str(k ^ 2 ) ) ) oTable:setItem( k - 1, 1, oCell ) next k

oLabel := QStringList() oLabel:append( "N." ) oLabel:append( "Square" )

oTable:setHorizontalHeaderLabels( oLabel )

oWnd:show() QApplication():exec()

RETURN

QInputDialog - Input Dialog windowThe following example uses a input dialog window to insert values into the program.

PROCEDURE Main()

LOCAL oWnd LOCAL cString LOCAL oDialog

oWnd := QMainWindow()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

84 de 195 13/02/2013 18:56

Page 85: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oDialog := QInputDialog() cString := oDialog:getText( oWnd, "Title", "What's your name?" ) oWnd:setWindowTitle( cString )

oWnd:show() QApplication():exec()

RETURN

QColorDialog - Color DialogThe following example shows how to use a color dialog to change the color of a textlabel.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

85 de 195 13/02/2013 18:56

Page 86: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd, oButton LOCAL oColorDialog, oText

oWnd := QMainWindow() oWnd:resize( 300, 200 ) oWnd:setWindowTitle( "Giovanni" )

oText := QLabel( oWnd ) oText:setText( "<h1>Hello World</h1>" ) oText:move( 20, 20 ) oText:resize( 250, 50 ) oButton := QPushButton( oWnd ) oButton:move( 180, 30 ) oButton:setText( "Change Color" ) oButton:Connect( "clicked()", { || oColorDialog:open() } )

oColorDialog := QColorDialog( oWnd ) oColorDialog:Connect( "currentColorChanged(QColor)", { ||change( oColorDialog,oText ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE change( oCd, cT )

LOCAL oPalette

oPalette := QPalette() oPalette:SetColor( QPalette_WindowText, oCd:currentColor() ) cT:setPalette( oPalette )

RETURN

QProgressBar - Progress BarThe following example shows use of a progress bar. It' useful during a long counting orelaboration of big archives.

PROCEDURE Main()

LOCAL oBar LOCAL k

oBar := QProgressBar() oBar:resize( 400, 50 ) oBar:move( 50, 50 ) oBar:setRange( 1, 500000 ) oBar:setWindowTitle( "Wait..." ) oBar:Show() oBar:repaint()

for k := 1 TO 500000 oBar:setValue( k ) next k

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

86 de 195 13/02/2013 18:56

Page 87: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oBar:quit() QApplication():exec()

RETURN

QProgressBar - Progress Bar in a widgetThe following example shows use of a progress bar in a widget.

PROCEDURE Main()

LOCAL oWnd LOCAL oBar LOCAL k

oWnd := QMainWindow() oWnd:resize( 400, 100 ) oWnd:show()

oBar := QProgressBar( oWnd ) oBar:resize( 300, 20 ) oBar:move( 50, 25 ) oBar:setRange( 1, 500000 ) oBar:Show()

for k := 1 TO 500000 oBar:setValue( k ) next k

QApplication():exec()

RETURN

HTML - Tag HTMLThe following example shows how to use tag HTML to change the color, size and aspectof text of other objects.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

87 de 195 13/02/2013 18:56

Page 88: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oText

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oText := QLabel( oWnd ) oText:setText( "<font color=#FF0000 size=7>Gio</font>" ) oText:move( 10, 10 ) oText:resize( 280, 100 )

oWnd:show() QApplication():exec()

RETURN

HTML - Tag HTMLThe following example shows how to use tag HTML, like ordered list, text formatting andbreak row.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

88 de 195 13/02/2013 18:56

Page 89: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oLabel, cString

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

cString := "<font color=#FF0000 size=6>HTML and QLabel</font>" cString := cString + "<br><br>" cString := cString + "<b>This is an ordered list</b><br>" cString := cString + "<ol>" cString := cString + "<li>Dog</li>" cString := cString + "<li>Cat</li>" cString := cString + "<li>Bird</li>" cString := cString + "</ol>" cString := cString + "<hr>"

oLabel := QLabel( oWnd ) oLabel:resize( 200, 150 ) oLabel:move( 20, 20 ) oLabel:setText( cString )

oWnd:show() QApplication():exec()

RETURN

HTML - Tag HTML and ImagesThe following example shows how to insert an image with the IMG tag HTML.

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel LOCAL cString

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

cString := "<img src='logo_google.bmp'>" cString := cString + "<br><br>" cString := cString + "<img src='logo_google.bmp' width=70>"

oLabel := QLabel( oWnd ) oLabel:resize( 200, 150 ) oLabel:move( 20, 20 ) oLabel:setText( cString )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

89 de 195 13/02/2013 18:56

Page 90: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:show() QApplication():exec()

RETURN

HTML - Tag HTML and subscriptThe following example shows how to use a subscript with the text.

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel LOCAL oString

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 600, 100 )

oString := "<font size=5 color=#0000AA>" oString := oString + "The chemical formula of water is H<sub>2</sub>O" oString := oString + "</font>"

oLabel := QLabel( oWnd ) oLabel:resize( 600, 100 ) oLabel:move( 0, 0 ) oLabel:setText( oString ) oWnd:show() QApplication():exec()

RETURN

QSlider - Slider with valueThe following example shows a slider that changes the value of a Lcd display. Values arebetween 0 and 99.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

90 de 195 13/02/2013 18:56

Page 91: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oSlider LOCAL oLcd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 240, 200 )

oLcd := QLCDNumber( oWnd ) oLcd:resize( 200, 120 ) oLcd:move( 20, 20 )

oSlider := QSlider( oWnd ) oSlider:resize( 211, 21 ) oSlider:move( 10, 160 ) oSlider:setMinimum( 0 ) oSlider:setMaximum( 99 ) oSlider:setSingleStep( 1 ) oSlider:setValue( 0 ) oSlider:setOrientation( Qt_Horizontal ) oSlider:Connect( "valueChanged(int)", { |x| oLcd:display( x ) } )

oWnd:show() QApplication():exec()

RETURN

QSlider - Sliders RGBThe following example uses three sliders to change the RGB color of a text.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

91 de 195 13/02/2013 18:56

Page 92: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL window LOCAL font LOCAL oSliderRed, oSliderGreen, oSliderBlu LOCAL oText

window := QMainWindow() window:resize( 320, 400 ) window:setWindowTitle( "Giovanni" )

font := QFont() font:setPointSize( 30 ) font:setBold( .T. )

oText := QLabel( window ) oText:setText( "Colors" ) oText:move( 100, 10 ) oText:resize( 200, 100 ) oText:setfont( font )

oSliderRed := QSlider( window ) oSliderRed:resize( 30, 200 ) oSliderRed:move( 100, 120 ) oSliderRed:setMinimum( 0 ) oSliderRed:setMaximum( 255 ) oSliderRed:setSingleStep( 1 ) oSliderRed:setPageStep( 10 ) oSliderRed:setValue( 0 ) oSliderRed:Connect( "valueChanged(int)", { || change_colors( oText,oSliderRed,oSliderGreen,oSliderBlu ) } )

oSliderGreen := QSlider( window ) oSliderGreen:resize( 30, 200 ) oSliderGreen:move( 150, 120 ) oSliderGreen:setMinimum( 0 ) oSliderGreen:setMaximum( 255 ) oSliderGreen:setSingleStep( 1 ) oSliderGreen:setPageStep( 10 ) oSliderGreen:setValue( 0 ) oSliderGreen:Connect( "valueChanged(int)", { || change_colors( oText,oSliderRed,oSliderGreen,oSliderBlu ) } )

oSliderBlu := QSlider( window ) oSliderBlu:resize( 30, 200 ) oSliderBlu:move( 200, 120 ) oSliderBlu:setMinimum( 0 ) oSliderBlu:setMaximum( 255 ) oSliderBlu:setSingleStep( 1 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

92 de 195 13/02/2013 18:56

Page 93: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oSliderBlu:setPageStep( 10 ) oSliderBlu:setValue( 0 ) oSliderBlu:Connect( "valueChanged(int)", { || change_colors( oText,oSliderRed,oSliderGreen,oSliderBlu ) } )

window:show() QApplication():exec()

RETURN

PROCEDURE change_colors( oT, oRed, oGre, oBlu )

LOCAL oPalette

oPalette := QPalette() oPalette:SetColor( QPalette_WindowText, QColor( oRed:value , oGre:value , oBlu:value ) )

oT:setPalette( oPalette )

RETURN

QSlider - Sliders synchronizationThe following example shows how to synchronize two sliders, so that moving a slider, itmoves the other.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oSlider1, oSlider2

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 240, 200 )

oSlider1 := QSlider( oWnd ) oSlider1:resize( 211, 21 ) oSlider1:move( 10, 50 ) oSlider1:setMinimum( 0 ) oSlider1:setMaximum( 99 ) oSlider1:setSingleStep( 1 ) oSlider1:setValue( 0 ) oSlider1:setOrientation( Qt_Horizontal ) oSlider1:Connect( "valueChanged(int)", { |x|oSlider2:setValue( x ) } )

oSlider2 := QSlider( oWnd ) oSlider2:resize( 211, 21 ) oSlider2:move( 10, 100 ) oSlider2:setMinimum( 0 ) oSlider2:setMaximum( 99 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

93 de 195 13/02/2013 18:56

Page 94: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oSlider2:setSingleStep( 1 ) oSlider2:setValue( 0 ) oSlider2:setOrientation( Qt_Horizontal ) oSlider2:Connect( "valueChanged(int)", { |x|oSlider1:setValue( x ) } )

oWnd:show() QApplication():exec()

RETURN

QDial - Simple WheelThe following example uses a QDial control, to modify any value. It is a beautiful controland it can be used in many occasions.

PROCEDURE Main()

LOCAL oWnd,oWheel oWnd := QMainWindow() oWnd:resize( 400, 300 ) oWnd:setWindowTitle( "Finestra di Giovanni" )

oWheel := QDial( oWnd ) oWheel:move( 100, 50 ) oWheel:resize( 200, 200 ) oWheel:setMinimum( 0 ) oWheel:setMaximum( 10 ) oWheel:setSingleStep( 1 ) oWheel:setWrapping( .F. )

oWnd:show() QApplication():exec()

RETURN

QDial - Wheel with a LCD DisplayThe following example uses a QDial control, to modify the value in a LCD display.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

94 de 195 13/02/2013 18:56

Page 95: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oWheel, oDisplay oWnd := QMainWindow() oWnd:resize( 400, 300 ) oWnd:setWindowTitle( "Finestra di Giovanni" )

oDisplay := QLCDNumber( oWnd ) oDisplay:resize( 100, 50 ) oDisplay:move( 150, 20 ) oDisplay:display( 0 )

oWheel := QDial( oWnd ) oWheel:move( 100, 80 ) oWheel:resize( 200, 200 ) oWheel:setMinimum( 0 ) oWheel:setMaximum( 10 ) oWheel:setSingleStep( 1 ) oWheel:setWrapping( .F. ) oWheel:Connect( "valueChanged(int)", { |x| oDisplay:display( x ) } )

oWnd:show() QApplication():exec()

RETURN

QSpinBox - Spin ControlThe following example uses a spin control, to modify the size of a text. Values can betyped or chosen with the arrows.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

95 de 195 13/02/2013 18:56

Page 96: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oFont LOCAL oText LOCAL oChanger

oWnd := QMainWindow() oWnd:resize( 320, 200 ) oWnd:setWindowTitle( "Giovanni" )

oFont := QFont() oFont:setPointSize( 30 ) oText := QLabel( oWnd ) oText:setText( "Text" ) oText:move( 10, 10 ) oText:resize( 280, 100 ) oText:setFont( oFont )

oChanger := QSpinBox( oWnd ) oChanger:move( 50, 150 ) oChanger:resize( 50, 25 ) oChanger:Connect( "valueChanged(int)", { |x|change_dimension(x,oFont,oText) } ) oChanger:setMinimum( 1 ) oChanger:setMaximum( 72 ) oChanger:setSingleStep( 1 ) oChanger:setValue( 30 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE change_dimension(nD,oF,oT)

oF:setPointSize( nD ) oT:setFont( oF )

RETURN

QComboBox - ComboBoxThe following example creates a combobox, with many items. User can select any item.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

96 de 195 13/02/2013 18:56

Page 97: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oCombo

oWnd := QMainWindow() oWnd:resize( 320, 200 ) oWnd:setWindowTitle( "Giovanni" )

oCombo := QComboBox( oWnd ) oCombo:move( 100, 50 ) oCombo:resize( 100, 25 ) oCombo:addItem( "Francia" ) oCombo:addItem( "Italia" ) oCombo:addItem( "U.S.A." ) oCombo:addItem( "Germania" ) oCombo:addItem( "Belgio" ) oCombo:addItem( "Spagna" ) oCombo:addItem( "Portogallo" ) oCombo:addItem( "Islanda" )

oWnd:show() QApplication():exec()

RETURN

QComboBox - ComboBox with UpdateThe following example creates a combobox, with many items. User can select any item.When selected, it's shown in a label.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

97 de 195 13/02/2013 18:56

Page 98: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oCombo, oLabel

oWnd := QMainWindow() oWnd:resize( 320, 200 ) oWnd:setWindowTitle( "Giovanni" )

oCombo := QComboBox( oWnd ) oCombo:move( 20, 20 ) oCombo:resize( 100, 25 ) oCombo:addItem( "Francia" ) oCombo:addItem( "Italia" ) oCombo:addItem( "U.S.A." ) oCombo:addItem( "Germania" ) oCombo:addItem( "Belgio" ) oCombo:addItem( "Spagna" ) oCombo:addItem( "Portogallo" ) oCombo:addItem( "Islanda" ) oCombo:Connect( "currentIndexChanged(int)", { ||oLabel:setText( oCombo:currentText() ) } )

oLabel := QLabel( oWnd ) oLabel:move( 200, 150 )

oWnd:show() QApplication():exec()

RETURN

QComboBox - Populating a ComboBox from a DBFThe following example creates a combobox, with many items. The items are appendedfrom a DBF database.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

98 de 195 13/02/2013 18:56

Page 99: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oCombo

oWnd := QMainWindow() oWnd:resize( 320, 200 ) oWnd:setWindowTitle( "Giovanni" )

oCombo := QComboBox( oWnd ) oCombo:move( 50, 50 ) oCombo:resize( 200, 25 )

USE cities

DO WHILE .NOT. Eof() oCombo:addItem( cities -> city ) SKIP ENDDO

USE

oWnd:show() QApplication():exec()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

99 de 195 13/02/2013 18:56

Page 100: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QFontComboBox - ComboBox with FontsThe following example creates a combobox, with a set of system fonts. The text ischanged with the selected font.

PROCEDURE Main()

LOCAL oWnd LOCAL oText LOCAL oCombo

oWnd := QMainWindow() oWnd:resize( 320, 200 ) oWnd:setWindowTitle( "Giovanni" )

oText := QLabel( oWnd ) oText:setText( "Ciao a tutti" ) oText:resize( 200, 80 ) oText:move( 50, 20 )

oCombo := QFontComboBox( oWnd ) oCombo:move( 50, 100 ) oCombo:resize( 200, 25 ) oCombo:Connect( "currentFontChanged(QFont)", { ||oText:setFont( oCombo:currentFont() ) } )

oWnd:show() QApplication():exec()

RETURN

QLCDNumber - LCD DisplayThe following example creates a nice LCD display, to view numbers. It's properties canbe changed.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

100 de 195 13/02/2013 18:56

Page 101: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oButtonMinus, oButtonPlus, oLcd

oWnd := QMainWindow() oWnd:resize( 300, 200 ) oWnd:setWindowTitle( "Giovanni" )

oLcd := QLCDNumber( oWnd ) oLcd:move( 50, 50 ) oLcd:resize( 200, 50 )

oButtonMinus := QPushButton( oWnd ) oButtonMinus:resize( 30, 30 ) oButtonMinus:move( 70, 130 ) oButtonMinus:setText( "-" ) oButtonMinus:Connect( "clicked()", { || oLcd:display( oLcd:value() - 1 ) } )

oButtonPlus := QPushButton( oWnd ) oButtonPlus:resize( 30, 30 ) oButtonPlus:move( 200, 130 ) oButtonPlus:setText( "+" ) oButtonPlus:Connect( "clicked()", { || oLcd:display( oLcd:value() + 1 ) } )

oWnd:show() QApplication():exec()

RETURN

QLCDNumber - LCD with number in decimal, binary, hexdecimal and octal baseThe following example creates four LCD displays, that display a number in four bases:decimal, binary, hexdecimal and octal. The number is changed by a Spin Box.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

101 de 195 13/02/2013 18:56

Page 102: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main() LOCAL oWnd, oSpinBox LOCAL oLabel1, oLabel2, oLabel3, oLabel4 LOCAL oLcd1, oLcd2, oLcd3, oLcd4

oWnd := QMainWindow() oWnd:resize( 300, 300 ) oWnd:setWindowTitle( "Giovanni" )

oLcd1 := QLCDNumber( oWnd ) oLcd1:move( 60, 10 ) oLcd1:resize( 200, 50 ) oLcd1:SetMode( 1 )

oLcd2 := QLCDNumber( oWnd ) oLcd2:move( 60, 70 ) oLcd2:resize( 200, 50 ) oLcd2:SetMode( 3 )

oLcd3 := QLCDNumber( oWnd ) oLcd3:move( 60, 130 ) oLcd3:resize( 200, 50 ) oLcd3:SetMode( 0 )

oLcd4 := QLCDNumber( oWnd ) oLcd4:move( 60, 190 ) oLcd4:resize( 200, 50 ) oLcd4:SetMode( 2 )

oLabel1 := QLabel( oWnd ) oLabel1:setText( "Dec" ) oLabel1:move( 25, 20 )

oLabel2 := QLabel( oWnd ) oLabel2:setText( "Bin" ) oLabel2:move( 25, 80 )

oLabel3 := QLabel( oWnd ) oLabel3:setText( "Hex" ) oLabel3:move( 25, 140 )

oLabel4 := QLabel( oWnd ) oLabel4:setText( "Oct" ) oLabel4:move( 25, 200 )

oSpinBox := QSpinBox( oWnd ) oSpinBox:move( 125, 260 ) oSpinBox:resize( 50, 25 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

102 de 195 13/02/2013 18:56

Page 103: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oSpinBox:Connect( "valueChanged(int)", { |x|disp( x,oLcd1, oLcd2, oLcd3, oLcd4 ) } ) oSpinBox:setMinimum( 0 ) oSpinBox:setMaximum( 31 ) oSpinBox:setSingleStep( 1 ) oSpinBox:setValue( 0 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE DISP( x, oD1, oD2, oD3, oD4 )

oD1:display( x ) oD2:display( x ) oD3:display( x ) oD4:display( x )

RETURN

QLCDNumber - Colored LCD DisplayThe following example creates three nice colored LCD displays.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd, oLcd1, oLcd2, oLcd3, oPalette

oWnd := QMainWindow() oWnd:resize( 300, 200 ) oWnd:setWindowTitle( "Giovanni" )

oPalette := QPalette()

oPalette:SetColor( QPalette_WindowText, QColor( 255,0,0 ) ) oLcd1 := QLCDNumber( oWnd ) oLcd1:move( 50, 10 ) oLcd1:resize( 200, 50 ) oLcd1:display( 1967 ) oLcd1:setPalette( oPalette )

oPalette:SetColor( QPalette_WindowText, QColor( 0,150,0 ) ) oLcd2 := QLCDNumber( oWnd ) oLcd2:move( 50, 70 ) oLcd2:resize( 200, 50 ) oLcd2:display( 1999 ) oLcd2:setPalette( oPalette )

oPalette:SetColor( QPalette_WindowText, QColor( 50,50,255 ) )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

103 de 195 13/02/2013 18:56

Page 104: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oLcd3 := QLCDNumber( oWnd ) oLcd3:move( 50, 130 ) oLcd3:resize( 200, 50 ) oLcd3:display( 2007 ) oLcd3:setPalette( oPalette )

oWnd:show() QApplication():exec()

RETURN

QLCDNumber - How to display numbers and textDigits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S, 6, 7, 8, 9/g, minus, decimalpoint, A, B, C, D, E, F, h, H, L, o, P, r, u, U, Y, colon, degree sign (which is specified assingle quote in the string) and space.

PROCEDURE Main()

LOCAL oWnd, oLcd

oWnd := QMainWindow() oWnd:resize( 700, 200 ) oWnd:setWindowTitle( "Giovanni" )

oLcd := QLCDNumber( oWnd ) oLcd:move( 50, 50 ) oLcd:resize( 600, 50 ) oLcd:setDigitCount ( 30 ) oLcd:display ( "0123456789-. ABCDEFhHLoPruUY:'" )

oWnd:show() QApplication():exec()

RETURN

QLCDNumber - Digital clock with LCDThe following example shows how to create a real time digital clock.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

104 de 195 13/02/2013 18:56

Page 105: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oClock LOCAL oLcd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oLcd := QLCDNumber( oWnd ) oLcd:move( 50, 50 ) oLcd:resize( 300, 100 ) oLcd:setDigitCount( 8 ) oLcd:setStyleSheet( "color: #FF0000;" )

oClock := QTimer() oClock:Connect( "timeout()", { || print_clock( oLcd ) } ) oClock:start( 1000 )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE print_clock( oL )

LOCAL stringa LOCAL hou, min, sec

hou := SubStr( Time(), 1, 2 ) min := SubStr( Time(), 4, 2 ) sec := SubStr( Time(), 7, 2 )

stringa := hou + ":" + min + ":" + sec

oL:display ( stringa )

RETURN

QRadioButton - Radio ButtonsThe following example shows how to use a radio button, with three options. Every optionis connected to a function.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

105 de 195 13/02/2013 18:56

Page 106: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oButton1, oButton2, oButton3

oWnd := QMainWindow() oWnd:resize( 400, 300 ) oWnd:setWindowTitle( "Giovanni" ) oButton1 := QRadioButton( oWnd ) oButton1:move( 100, 50 ) oButton1:setText( "Si" ) oButton1:Connect( "clicked()", { || message( "SI" ) } )

oButton2 := QRadioButton( oWnd ) oButton2:move( 100, 80 ) oButton2:setText( "No" ) oButton2:Connect( "clicked()", { || message( "NO" ) } )

oButton3 := QRadioButton( oWnd ) oButton3:move( 100, 110 ) oButton3:setText( "Non so" ) oButton3:Connect( "clicked()", { || message( "NON SO" ) } ) oWnd:show() QApplication():exec()

RETURN

PROCEDURE message( cMsg )

LOCAL oBox

oBox := QMessageBox() oBox:setInformativeText( cMsg ) oBox:setWindowTitle( "Informazione" )

oBox:exec()

RETURN

QRadioButton - Radio Buttons and imagesThe following example shows how to use a radio button, with three options. Every optionis connected to a function, showing an image.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

106 de 195 13/02/2013 18:56

Page 107: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oImg LOCAL oButton1, oButton2, oButton3

oWnd := QMainWindow() oWnd:resize( 400, 200 ) oWnd:setWindowTitle( "Giovanni" ) oButton1 := QRadioButton( oWnd ) oButton1:move( 100, 50 ) oButton1:setText( "Washington" ) oButton1:Connect( "clicked()", { || message( oWnd, oImg, "washington.bmp" ) } )

oButton2 := QRadioButton( oWnd ) oButton2:move( 100, 80 ) oButton2:setText( "Napoleon" ) oButton2:Connect( "clicked()", { || message( oWnd, oImg, "napoleon.bmp" ) } )

oButton3 := QRadioButton( oWnd ) oButton3:move( 100, 110 ) oButton3:setText( "Garibaldi" ) oButton3:Connect( "clicked()", { || message( oWnd, oImg, "garibaldi.bmp" ) } ) oImg := QLabel( oWnd ) oImg:move( 250, 50 ) oImg:resize( 80, 80 ) oImg:setStyleSheet( "border: 2px solid #0000ff;" ) oWnd:show() QApplication():exec()

RETURN

PROCEDURE message( oW, oI, cMsg )

oW:setWindowTitle( cMsg ) oI:SetPixmap( QPixmap( cMsg ) )

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

107 de 195 13/02/2013 18:56

Page 108: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QVBoxLayout - Vertical LayoutThe following example uses the vertical layouts, to place controls without to specify anyposition. The placing and position is automatic.

PROCEDURE Main()

LOCAL oW, oLay LOCAL oT0, oT1, oT2, oT3, oT4, oT5, oT6, oB0

oW := QWidget() oW:setWindowTitle( "Finestra di Giovanni" ) oW:resize( 300, 200 )

oT0 := QLabel() oT0:setText( "Hello World - Ciao mondo" )

oT1 := QLabel() oT1:setText( "Line 2 - Linea 2" )

oT2 := QLabel() oT2:setText( "Hello again - Nuovamente Ciao" )

oT3 := QLabel() oT3:setText( "Line 3 - Linea 3" )

oT4 := QLabel() oT4:setText( "Ciao ancora una volta!" )

oT5 := QLabel() oT5:setText( "Line 5 - Linea 5" )

oT6 := QLabel() oT6:setText( "Line 6 - Linea 6" )

oB0 := QPushButton() oB0:setText( "Clicca per terminare / Click to quit" ) oB0:Connect( "clicked()", { || QApplication():quit() } )

oLay := QVBoxLayout( oW ) oLay:addWidget( oT0 ) oLay:addWidget( oT1 ) oLay:addWidget( oT2 ) oLay:addWidget( oT3 ) oLay:addWidget( oT4 ) oLay:addWidget( oT5 ) oLay:addWidget( oT6 ) oLay:addWidget( oB0 )

oW:show() QApplication():exec()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

108 de 195 13/02/2013 18:56

Page 109: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QHBoxLayout - Horizontal LayoutThe following example uses the horizontal layouts, to place controls without to specifyany position. The placing and position is automatic.

PROCEDURE Main()

LOCAL oW, oLay LOCAL oP0, oP1, oP2, oP3, oP4, oP5, oP6

oW := QWidget() oW:setWindowTitle( "Finestra di Giovanni" ) oW:resize( 400, 100 )

oP0 := QPushButton() oP0:setText( "OK 1" )

oP1 := QPushButton() oP1:setText( "OK 2" )

oP2 := QPushButton() oP2:setText( "OK 3" )

oP3 := QPushButton() oP3:setText( "OK 4" )

oP4 := QPushButton() oP4:setText( "OK 5" )

oP5 := QPushButton() oP5:setText( "OK 6" )

oP6 := QPushButton() oP6:setText( "OK 7" )

oLay := QHBoxLayout( oW ) oLay:addWidget( oP0 ) oLay:addWidget( oP1 ) oLay:addWidget( oP2 ) oLay:addWidget( oP3 ) oLay:addWidget( oP4 ) oLay:addWidget( oP5 ) oLay:addWidget( oP6 )

oW:show() QApplication():exec()

RETURN

QLineEdit - Line EditThe following example uses a line edit, to insert and view any data.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

109 de 195 13/02/2013 18:56

Page 110: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oName, oLabel

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 150 )

oLabel := QLabel( oWnd ) oLabel:setText( "Name" ) oLabel:move( 50, 50 ) oLabel:resize( 100, 20 )

oName := QLineEdit( oWnd ) oName:move( 160, 50 ) oName:resize( 150, 20 )

oWnd:show() QApplication():exec()

RETURN

QLineEdit - Array of Line EditThe following example uses many line edits, stored in an array, to insert and view data.

PROCEDURE Main()

LOCAL oWnd, oName[16], k

oWnd := QMainWindow()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

110 de 195 13/02/2013 18:56

Page 111: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 250 )

for k := 1 TO 8 oName[k] := QLineEdit( oWnd ) oName[k]:move( 20, 22 * k ) oName[k]:resize( 150, 20 ) next k

for k := 9 TO 16 oName[k] := QLineEdit( oWnd ) oName[k]:move( 180, 22 * ( k - 8 ) ) oName[k]:resize( 150, 20 ) next k

oWnd:show() QApplication():exec()

RETURN

QLineEdit - Merging two Line EditsThe following example uses two line edits, to insert and view data. By pressing thebutton, the values of the two Line Edits are merged and added to a third Line Edit.

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel1, oLabel2 LOCAL oButton LOCAL oName, oSurname, oSum

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 150 )

oLabel1 := QLabel( oWnd ) oLabel1:setText( "First Name" ) oLabel1:move( 20, 20 ) oLabel1:resize( 100, 20 ) oName := QLineEdit( oWnd ) oName:move( 20, 40 ) oName:resize( 100, 20 )

oLabel2 := QLabel( oWnd ) oLabel2:setText( "Last Name" ) oLabel2:move( 150, 20 ) oLabel2:resize( 100, 20 ) oSurname := QLineEdit( oWnd ) oSurname:move( 150, 40 ) oSurname:resize( 100, 20 )

oButton := QPushButton( oWnd ) oButton:move( 20, 85 ) oButton:setText( "Merge the fields" ) oButton:connect( "clicked()", { || merge( oName,oSurname,oSum ) } )

oSum := QLineEdit( oWnd ) oSum:move( 150, 90 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

111 de 195 13/02/2013 18:56

Page 112: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oSum:resize( 180, 20 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE merge( oNam, oSur, oSum )

oSum:setText( oNam:text() + Space( 1 ) + oSur:text() )

RETURN

QLineEdit - Resetting Line EditsThe following example shows how to reset and clear line edits.

PROCEDURE Main()

LOCAL oWnd LOCAL oButton LOCAL oF1, oF2, oF3, oF4, oF5, oF6, oF7, oF8

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 270, 300 ) oF1 := QLineEdit( oWnd ) oF1:move( 10, 10 ) oF1:resize( 200, 20 )

oF2 := QLineEdit( oWnd ) oF2:move( 10, 40 ) oF2:resize( 200, 20 )

oF3 := QLineEdit( oWnd ) oF3:move( 10, 70 ) oF3:resize( 250, 20 )

oF4 := QLineEdit( oWnd ) oF4:move( 10, 100 ) oF4:resize( 60, 20 )

oF5 := QLineEdit( oWnd ) oF5:move( 10, 130 ) oF5:resize( 100, 20 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

112 de 195 13/02/2013 18:56

Page 113: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oF6 := QLineEdit( oWnd ) oF6:move( 10, 160 ) oF6:resize( 50, 20 )

oF7 := QLineEdit( oWnd ) oF7:move( 10, 190 ) oF7:resize( 200, 20 )

oF8 := QLineEdit( oWnd ) oF8:move( 10, 220 ) oF8:resize( 250, 20 )

oButton := QPushButton( oWnd ) oButton:move( 100, 250 ) oButton:resize( 85, 40 ) oButton:setText( "Clear Fields" ) oButton:connect( "clicked()", { || clear_all(oF1, oF2, oF3, oF4, oF5, oF6, oF7, oF8) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE clear_all(oF1, oF2, oF3, oF4, oF5, oF6, oF7, oF8)

oF1:clear() // Clear the field oF2:setText( "" ) // Clear the field oF3:clear() oF4:clear() oF5:clear() oF6:clear() oF7:clear() oF8:clear()

RETURN

QLineEdit - PasswordThe following example shows how to insert a password into a line edit. The asterisks willbe shown instead of the characters actually entered.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oPasswd, oLabel

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 150 )

oLabel := QLabel( oWnd ) oLabel:setText( "Type a password" ) oLabel:move( 50, 50 ) oLabel:resize( 100, 20 )

oPasswd := QLineEdit( oWnd ) oPasswd:move( 160, 50 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

113 de 195 13/02/2013 18:56

Page 114: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oPasswd:resize( 150, 20 ) oPasswd:setEchoMode( QLineEdit_Password )

oWnd:show() QApplication():exec()

RETURN

QLineEdit - Order of inputsThe following example shows how to change the order of tabulation, simply changingthe position of QLineEdit objects, in the source file.

PROCEDURE Main()

LOCAL oWnd LOCAL oLineEdit1, oLineEdit2, oLineEdit3, oLineEdit4

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oLineEdit1 := QLineEdit( oWnd ) oLineEdit1:move( 50, 50 ) oLineEdit1:resize( 300, 20 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

114 de 195 13/02/2013 18:56

Page 115: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oLineEdit2 := QLineEdit( oWnd ) oLineEdit2:move( 50, 100 ) oLineEdit2:resize( 300, 20 )

oLineEdit3 := QLineEdit( oWnd ) oLineEdit3:move( 50, 150 ) oLineEdit3:resize( 300, 20 )

oLineEdit4 := QLineEdit( oWnd ) oLineEdit4:move( 50, 200 ) oLineEdit4:resize( 300, 20 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE Main()

LOCAL oWnd LOCAL oLineEdit1, oLineEdit2, oLineEdit3, oLineEdit4

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oLineEdit3 := QLineEdit( oWnd ) oLineEdit3:move( 50, 150 ) oLineEdit3:resize( 300, 20 )

oLineEdit2 := QLineEdit( oWnd ) oLineEdit2:move( 50, 100 ) oLineEdit2:resize( 300, 20 )

oLineEdit4 := QLineEdit( oWnd ) oLineEdit4:move( 50, 200 ) oLineEdit4:resize( 300, 20 )

oLineEdit1 := QLineEdit( oWnd ) oLineEdit1:move( 50, 50 ) oLineEdit1:resize( 300, 20 )

oWnd:show() QApplication():exec()

RETURN

QLineEdit - Set Input MaskThe following example shows how to set a mask in a QLineEdit, to filter the charactersinserted. The input mask is similar to PICTURE in @ SAY ... GET command.

PROCEDURE Main()

LOCAL oWnd

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

115 de 195 13/02/2013 18:56

Page 116: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

LOCAL oNumber, oLabel

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 150 )

oLabel := QLabel( oWnd ) oLabel:setText( "Only Six Numbers" ) oLabel:move( 50, 50 ) oLabel:resize( 100, 20 )

oNumber := QLineEdit( oWnd ) oNumber:move( 160, 50 ) oNumber:resize( 150, 20 ) oNumber:setInputMask( "999999" )

oWnd:show() QApplication():exec()

RETURN

Character Meaning---------------------------------------------------------------------------------------------A ASCII alphabetic character required. A-Z, a-z.a ASCII alphabetic character permitted but not required.N ASCII alphanumeric character required. A-Z, a-z, 0-9.n ASCII alphanumeric character permitted but not required.X Any character required.x Any character permitted but not required.9 ASCII digit required. 0-9.0 ASCII digit permitted but not required.D ASCII digit required. 1-9.d ASCII digit permitted but not required (1-9).# ASCII digit or plus/minus sign permitted but not required.H Hexadecimal character required. A-F, a-f, 0-9.h Hexadecimal character permitted but not required.B Binary character required. 0-1.b Binary character permitted but not required.> All following alphabetic characters are uppercased.< All following alphabetic characters are lowercased.! Switch off case conversion.\ Use \ to escape the special characters listed above to use them as separators.---------------------------------------------------------------------------------------------The mask consists of a string of mask characters and separators, optionally followedby a semicolon and the character used for blanks. The blank characters are alwaysremoved from the text after editing.

Examples:

Mask Notes--------------------------------------------------------------------000.000.000.000;_ IP address; blanks are _HH:HH:HH:HH:HH:HH;_ MAC address0000-00-00 ISO Date; blanks are space>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# License number; blanks are - and all characters are converted to uppercase

QLineEdit - How to Hide and Show a line editThe following example shows how to to hide and show a line edit, using a button. Alsothe label of the button changes, if it's pressed.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

116 de 195 13/02/2013 18:56

Page 117: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oNumber1, oButton

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oNumber1 := QLineEdit( oWnd ) oNumber1:move( 150, 50 ) oNumber1:resize( 100, 20 )

oButton := QPushButton( oWnd ) oButton:setText( "Hide Line Edit" ) oButton:move( 125, 150 ) oButton:resize( 150, 25 ) oButton:Connect( "clicked()", { || HideShow( oNumber1, oButton ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE HideShow ( oN, oB )

oN:setVisible ( .NOT. oN:isVisible() ) IF .NOT. oN:isVisible() oB:setText( "Show Line Edit" ) ELSE oB:setText( "Hide Line Edit" ) END IF

RETURN

QLineEdit - Navigating with UP/DOWN keysBy default you can navigate across QLineEdits by TAB key. This example shows how tochange this behavior, using UP and DOWN cursor keys.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

117 de 195 13/02/2013 18:56

Page 118: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"PROCEDURE Main()

LOCAL oWnd LOCAL oLineEdit1, oLineEdit2, oLineEdit3

oWnd := QMAINWINDOW() oWnd:resize( 400, 300 ) oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:Connect( QEvent_KeyPress, {| oEvent | fKey( oEvent, oWnd ) } )

oLineEdit1 := QLINEEDIT( oWnd ) oLineEdit1:move( 50, 50 ) oLineEdit1:resize( 300, 20 )

oLineEdit2 := QLINEEDIT( oWnd ) oLineEdit2:move( 50, 100 ) oLineEdit2:resize( 300, 20 )

oLineEdit3 := QLINEEDIT( oWnd ) oLineEdit3:move( 50, 150 ) oLineEdit3:resize( 300, 20 )

oWnd:show() QAPPLICATION():exec()

RETURN

PROCEDURE fKey( oEvent, oWnd )

DO CASE CASE oEvent:key() == Qt_Key_Down QAPPLICATION():sendEvent( oWnd, QKEYEVENT( QEvent_KeyPress, Qt_Key_Tab, Qt_NoModifier ) ) CASE oEvent:key() == Qt_Key_Up QAPPLICATION():sendEvent( oWnd, QKEYEVENT( QEvent_KeyPress, Qt_Key_Backtab, Qt_NoModifier ) ) ENDCASE

RETURN

QTextEdit - Rich Text EditorThe following example shows a Rich Text editor and sets his text to bold, italic and size20, color blue.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

118 de 195 13/02/2013 18:56

Page 119: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oEditor, oFont

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oFont := QFont() oFont:setBold( .T. ) oFont:setItalic( .T. ) oFont:setPointSize( 20 )

oEditor := QTextEdit( oWnd ) oEditor:resize( 300, 200 ) oEditor:move( 50, 50 ) oEditor:setTextColor( QColor( 0,0,200 ) ) oEditor:setCurrentFont( oFont )

oWnd:show() QApplication():exec()

RETURN

QTextEdit - Ascii ArtThe following example shows how to draw with Ascii Art in a QTextEdit. The font usedmust be "Courier". The drawing is stored in a string.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

119 de 195 13/02/2013 18:56

Page 120: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"#define CR Chr( 13 )

PROCEDURE Main()

LOCAL oWnd, oEditor, oFont LOCAL cSt

cSt := "" cSt := cSt + " .,. " + CR cSt := cSt + " .,;CCCCCCCC>-;;. " + CR cSt := cSt + " ;CCC>>''';;;<>;;,.`-;. " + CR cSt := cSt + " ,CC>' .;''CCCCCCCCCCC>;,. " + CR

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

120 de 195 13/02/2013 18:56

Page 121: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

cSt := cSt + " ,cC> ,<CC>.''````''''''<CCC>. " + CR cSt := cSt + " .C'.;CCC>> ,cc$$$$$$$$$h.`'<>.;.. " + CR cSt := cSt + " ; ;CCC> ,c$$$$$$$$$$$$$$$c -.`'CCC, " + CR cSt := cSt + " ',<CC>'.z$$$$$$$$$$$$$$$$$$h.`-;,cCC> " + CR cSt := cSt + " ,cCC> c$$$$$$$$$$$$$$$$$$$??$c <CCCCC> .,<>;CCC;>. " + CR cSt := cSt + " `CCC'.$$$$$$$$$$$$$$$$'',;:::$h <CC''< .;<CCC''>>''.,;;,. " + CR cSt := cSt + " ;CCC>.$$$$$$$$$$$$$$F =',;=-?$$h <CC; .;CCCCCC>' .;CCCCCCCC; " + CR cSt := cSt + " <CCC'.$$$$$$????$$$$c' '. ,$$$h CCC, .,<C>>''', .;CCCCCCCCCCCCC, " + CR cSt := cSt + " <CCC'<$$F',r=-;-,?$$$.hcccc$$$$$$.`CC> `<C,.;CCC> <CCCCCCCCCCCCCCC, " + CR cSt := cSt + " CCC <$$cJ'P'' Jf<$$??$$$$$$$$$$$ C> ; C<CC'''C,cCCCCCCCCCCCC><CCC, " + CR cSt := cSt + " `>>> ?$$L_ - ,c$$i?$$<?$$$$$$$$$$ C, ,C' .,. <'''CCCCC><CCCC<C> CCCC " + CR cSt := cSt + " <C> '$$$$$$$$$$$$$$$h?$$$$$$$$$ CC <',$$$$cc$ ``'CCC> CCC>,cC <CCC " + CR cSt := cSt + " CC>>.`$$$$$$$$$$>J$$?>?$$$$$$$$ CC z?$$$$$$$h<C,. <C <CC <CC;.`'' " + CR cSt := cSt + " `C> >.`?$$$$$$$$h<,;,c$$?$$$$$$ C' ;L _`'?$$$$$$$$hr` C') CC(`<C,. " + CR cSt := cSt + " `<>.`; ?$$$$$$$$$???'.,c$$$$$','.,.. $$, $$$$$$$$$$$ `,c,`<C> CC " + CR cSt := cSt + " `;C>. '$$$$$$;ccc??73$$$$' > J$$$$F<$$$$$$$$$' ``'?$$$c `')>'CC,.' " + CR cSt := cSt + " `<CC> `?$$$$$$$$6$$$$$P'. <$$$$$F`$$$??$$$$$`?' '$$$$cr > C>>> " + CR cSt := cSt + " <>./>;'`-,`'?$$$$$$$$P',J$. $$$$$$F $??c;?>J$$hc,.,c$$$$' <>.'; " + CR cSt := cSt + " ``' ,r<$$$hc,,.`''.,c$$$$$ ''??$h ?hc`'=c$$$$$$$$$$$$',c' ' " + CR cSt := cSt + " zJ$$C;$$$$$$$$$$$$$$$$$$$:c, --,.' $L;,-cd$$$$$?????' -cc, " + CR cSt := cSt + " .,c$$$$$$$$$$$$$$$$$$$$$$$$$$:$$$cc `C,`?$$$$$$$??;it$' <$cc`?$c " + CR cSt := cSt + " .z$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$:$$$$$$c,`\..''''$$$P''_,ccc$$$L,$$c " + CR cSt := cSt + " z$$$$$$$$$$$$$$'.,.`' .`?$$$$$$$$$$$$$$$$$$c CC',$ ,cd$$$$$$$$$$$$$$ " + CR cSt := cSt + " $$$$$$$$$$$$$P' `'??$c,h.'?$$$$$$$$$$$$$$$$$.'' '.zJ$$$$$$$$$$$$$$$$$F " + CR cSt := cSt + " .`'$$$$$$$$$$ `?$$hc$$$$$h ?$$$$$$$$$$$$$$P',cd$$$$$$$$$$$$$$$$$$$$$$F " + CR cSt := cSt + " CC,.'?$$$$$$$ =ccc,J$$$$$$Lcc,.,,;,.```''',J$$$$$$$$$$$$$$$$$$$$$$$$$$. " + CR cSt := cSt + " CCCC>;.'?$$$$$- ''?$$$$$$$$$$$$$$$$$$$$$c$$$$$$$$$$$$$$$$$$$$$$$$$$$$$> " + CR cSt := cSt + " `'<CCCC>.'?$$$c`'??$$$$$?$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$P'$$$$$$$$$$$$? " + CR cSt := cSt + " CC;,.`<<<>,.,,,<;,.`''''`?$$$$$$$$$$$$$$$???$$$$$$$$P' zJ$$$$$$$$$??iJ " + CR cSt := cSt + " CCCCCCC>;.`<<CCCCCCCCC;<>;,.`'??$$$$$$C$$$$C$?$???'',c$$$$$$$$$$$$$$$$r " + CR cSt := cSt + " `<<CCCCCCCC>;. ``'<<<<<<>>''', --..`''`''??'' ,;;i$$$$$$$$$$$$$$$$$$$$F " + CR cSt := cSt + " C>;,.,,cC,.,,,;<>;;;,,, .;CCC,;> ,;;,. .,.,,. CCCC$$$$$$$$$$$$$$$$$$$>>c, " + CR cSt := cSt + " CCCC,`'<CCCCCCCCCCCCC' ,<CCCC'.;CCCC>''.,.`'< <CC$$$$$$$$$$$$$$$$$??><J$$c " + CR cSt := cSt + " CCCCCC>;.`'<<CCCCCC> ,CCC>'',-''<>''.;CCCCCC; <CC$$$$$$$$$$$$$$$$$C$$$$$$$ " + CR cSt := cSt + " ' `''.,,,;;,.`C''' <C>' ,-- .;;> CCCCCCCCCCC <CCC$$$$$$$$$$$$$$$$$$$$$$$$ " + CR cSt := cSt + " <CCCCCCCCCCCCC,.`'''.,,-'.;CCC,'> CCCCCCCCCCC,`CCC$$$$$$$$$$$$$$$$$$$$$$$$ " + CR cSt := cSt + " CCCCCCCCCCCCCCCC,.`''.,;<CCCCC>.> CCCCCCCCCCCC <CC$$$$$$$$$$$$$$$$$$$$$$$$ " + CR cSt := cSt + " CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC>, <CCCCCCCCCCCC> CC$$$$$$$$$$$$$$$$$$$$$$$$ " + CR cSt := cSt + " CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC > <CCCCCCCCCCCCC,`CC$$$?????'''''''''??$$$$ " + CR cSt := cSt + " CCCCCC>''CCCCCCCCCCCCCCCCCCCC> ; <CCCCCCCCCCCCCC,`'.,cccd$$$$$$$$$$$cc,'?$ " + CR cSt := cSt + " CCCCCCC CCCCCCCCCCCCCCCCCCCCC ;' CCCCCCCCCCCC>' ,c$$$$$$$$$$$$$$$$$$$$$h,$ " + CR cSt := cSt + " CCCCCCC `CCCCCCCCCCCCCCCCCCCC,< <CCCCCCCCCC>',c$$$$$$$$$$$$$$$$$$$$$$$$$$$ " + CR cSt := cSt + " CCCCCCC <<<CCCCCCCCCCCCCCCCC> <CCCCCCCCCC> $$$$$$$$$$$$$$$$$$$$$$$$$$$$$ " + CR cSt := cSt + " CCCCCC> <<<<CCCCCCCCCCCCCCC> <>.<CCCCCCCCC J$$$$$$$$$$$$$$$$$$$$$$'' '$$$ " + CR cSt := cSt + " CCCCCC <<<<<<<CCCCCCCCCC>>> <C'<CCCCCC>>> $$$$$$$$$$$$$$$$$$$$$'. '$c '$ " + CR cSt := cSt + " CCCCCC `<<<<<<<<<<<<<>>>>>>' ' <<<<<>>>>> $$$$$$$$$$$$$$$$$$$$$.`?b`?$c " + CR cSt := cSt + " CCCCCC -;-;-;-;-;-;-;-;;;;;,,,,,........ <$$$$$$$$$$$$$$??$$$$$$h.'h.'?$ " + CR cSt := cSt + " CCCCCC ,,;;;; ,;;, ,, ,,. `''''''''''''. J$$$$$$$$$$$$C?'J$$$$$$$$.`?h.' " + CR cSt := cSt + " CCCCC> ,cCCCC',cCC ;CC CCC> <>;;,, ;;, CCC $$$$$$$$$$$$$$$ ''?$F ..`'- ?$c " + CR cSt := cSt + " CCCCC CCCCC> CCCC CCC CCCC>'CCCCC, <C,'C> $$$$$$$$$$$$$$$ $ccc,`'$$hc, '$ " + CR cSt := cSt + " CCCC> <CCCCC'<CCCC,)CC <CCCC,`'CCCC,'CC;<C $$$$$$$$$$$$$$F,$$$$$$c, ''??' " + CR cSt := cSt + " '''' `<<CCCC <CCCC>'CC.`CCCC> <CCCCC,<CCCC $$$$$$$$$$$$$',$$$$$$$$$$c " + CR cSt := cSt + " CCC>' .;..`''<<CCCC,cCC CCCCC><CCCCCCCCCC>,$$$$$$$$$$$$',$$$$$$$$$$$$c " + CR cSt := cSt + " C> ,<CCCC>''.,;,,.```---<CCCCCCCCCCCCCCCC <$$$$$$$$$$$' $$$$$$$$$$$$$$c " + CR cSt := cSt + " CCCCCC>'.;<CCCCCCCCCC;;,, `'''<CCCC>>>''',J$$$$$$$$$' :, ?$$$$$$$$$$$$$ " + CR cSt := cSt + " CCCCC ,<CCCCCCCCCCCCCCC' z$$$cc,`' ,$c=$$$$$$$$$$?$' ::`: '$$$$$$$$$$$$c, " + CR cSt := cSt + " CCCCCCCCCCCCCCCCCCCCCC ,J$$$$$$$$$c,' .',??$$$$$$c `: .::. '$$$$$$$$$$$$ " + CR cSt := cSt + " CCCCCCCCCCCCCCCCCCCCC z$$$$$$$$$$$$$CC;,`,, $$$$$$ ..::'..::. '$$$$$$$$$C " + CR cSt := cSt + " CCCCCCCCCCCCCCCCCCCCC $$$$$$$$$$$$$$$$$CCcc,, '?$F .....:::... `?$$$$$$$>c " + CR cSt := cSt + " CCCCCCCCCCCCCCCCCCCCC ?$$??$$$$$$$$$$$$$$$C'?$hc ``:::': ``'``. '?$$$$$$$ " + CR cSt := cSt + " CCCCCCCCCCCCCCCCCCCCC> '??<$$$$$$$$$$$$$$$$$c,`?<> :..` ...`.::: J$$$$$$$$ " + CR cSt := cSt + " CCCCCCCCCCCC>>>>''''..,;, `'?$$$$$$$$$$$$F'?$$h.`?.`:: .:::'`,J$$$$$$P'' " + CR cSt := cSt + " `'''' .-;> `'!' <!'`.,;!;, '??$$$$.`'?$h.`?$$h. .`:'.. . ,$$$$$P''.: ` " + CR cSt := cSt + " !!,;, `<' - ``,;<!!'' ,;;;;,''?$$c,`?$$. '?$$.` :'' : P;J$$P .::' ` " + CR cSt := cSt + " !!!!!>;,`' .>',, `,;<!!! ;,-`.',!'''- '?$h.`?$h. '?$h. .'.: `'''. :..:::: " + CR cSt := cSt + " !!!!!!' ./'`.>',;!!!..' `!''`'.,;;;!!''- '== '?$c '?$r .:::':'' `''` .. " + CR cSt := cSt + " !!!!' .< ,;!' <!!!!!!' ``,;;!!!'``.,;;;!!,,,.,..`.,..,..,.. ,;;;!!!! " + CR cSt := cSt + " !!' ;!' ;'`,;!'' ;-',;!!!!!!;;!!!!!!!!!!!''''''''''''`!!!!!!!;;!!!!!!!! " + CR cSt := cSt + " ' .<' ;!' <!!! ,'' ' ,;!!!!!!!!!!!!!!!!!'`.,;;;;;;;;!!!;;;,.```!!!!!!!!!!! " + CR

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 510, 940 )

oFont := QFont( "Courier New", 6 )

oEditor := QTextEdit( oWnd ) oEditor:resize( 490, 920 ) oEditor:move( 10, 10 ) oEditor:setTextColor( QColor( 0,255,255 ) ) oEditor:setStyleSheet( "background-color: #000000" ) oEditor:setFont( oFont ) oEditor:setPlainText( cSt )

oWnd:show()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

121 de 195 13/02/2013 18:56

Page 122: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QApplication():exec()

RETURN

QEvent CloseThe following example shows how to intercept the Close Event. In this example, theclose window button is ignored and you can exit from the window with the user button("Quit") only .

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd, oButton1

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 ) oWnd:connect( QEvent_Close , { |x| x:ignore() } )

oButton1 := QPushButton( oWnd ) oButton1:setText( "Quit" ) oButton1:move( 50, 50 ) oButton1:Connect( "clicked()", { || QApplication():quit() } )

oWnd:show() QApplication():exec() RETURN

QEvent KeyPressThe following example shows how to capture a key pressed. The even can capture alsoShift, Alt and Ctr keys.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

122 de 195 13/02/2013 18:56

Page 123: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel, oLabel2

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 240, 200 ) oWnd:connect( QEvent_KeyPress , { |k| keypressed( k , oLabel2 ) } )

oLabel := QLabel( oWnd ) oLabel:setText( "Please press a key..." ) oLabel:move( 10, 10 ) oLabel:resize( 200, 50 )

oLabel2 := QLabel( oWnd ) oLabel2:move( 10, 100 ) oLabel2:resize( 220, 50 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE keypressed( x , oL )

LOCAL string

string := "You have pressed the key: " + "<br><br>" string := string + "VALUE= " + Str( x:key() ) + "<br>" string := string + "KEY= " + Chr( x:key() ) oL:setText( string )

RETURN

QEvent KeyPressThe following example shows how to move a window by pressing the arrow keys.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

123 de 195 13/02/2013 18:56

Page 124: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 240, 200 ) oWnd:connect( QEvent_KeyPress , { |k| keypressed( k , oWnd ) } )

oLabel := QLabel( oWnd ) oLabel:setText( "Press Arrow Keys to move the window..." ) oLabel:resize( 220, 20 ) oLabel:move( 10, 10 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE keypressed( kk , oW )

DO CASE CASE kk:key() == Qt_Key_Up oW:move( oW:x() , oW:y() - 4 ) CASE kk:key() == Qt_Key_Down oW:move( oW:x() , oW:y() + 4 ) CASE kk:key() == Qt_Key_Left oW:move( oW:x() - 4 , oW:y() ) CASE kk:key() == Qt_Key_Right oW:move( oW:x() + 4 , oW:y() ) ENDCASE

RETURN

QEvent MoveThe following example shows how to intercept the event of moving the window.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

124 de 195 13/02/2013 18:56

Page 125: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 180 ) oWnd:show() oWnd:connect( QEvent_Move , { || Message() } ) // After oWnd:show()

QApplication():exec()

RETURN

PROCEDURE Message()

LOCAL oMB

oMB := QMessageBox() oMB:setInformativeText( "You have moved the window" ) oMB:setWindowTitle( "Harbour-QT" ) oMB:exec() oMB := NIL

RETURN

QEvent ResizeThe following example shows how to intercept the event of resizing the window. Theobjects in the window are resized and repositioned proportionally.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

125 de 195 13/02/2013 18:56

Page 126: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd, oButton

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" ) oWnd:resize( 200, 180 ) oWnd:show() oWnd:connect( QEvent_Resize , { || pChange( oWnd,oButton ) } )

oButton := QPushButton( oWnd ) oButton:setText( "Quit" ) oButton:move( oWnd:width()/5, oWnd:height()/5 ) oButton:resize( oWnd:width()/6, oWnd:height()/6 ) oButton:show()

QApplication():exec()

RETURN

PROCEDURE pChange( oWnd, oButton )

oButton:resize( oWnd:width()/6, oWnd:height()/6 ) oButton:move( oWnd:width()/5, oWnd:height()/5 )

RETURN

QPainter - Drawing a face

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

126 de 195 13/02/2013 18:56

Page 127: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

The following example shows how to draw a face with primitives, like circles and lines.This source uses the class QPainter.

PROCEDURE Main()

LOCAL oWnd LOCAL oPixmap LOCAL oPainter LOCAL oLabel

oWnd := QWidget() oWnd:resize( 300, 200 ) oWnd:setWindowTitle( "Finestra di Giovanni" )

oPixmap := QPixmap( 100, 100 ) oPixmap:fill( QColor( 255,255,150 ) )

oPainter := QPainter( oPixmap ) oPainter:drawEllipse( QPointF( 50,50 ), 40, 40 ) // Face oPainter:drawEllipse( QPointF( 40,30 ), 5, 5 ) // Eye oPainter:drawEllipse( QPointF( 40,30 ), 1, 1 ) // Eye center oPainter:drawEllipse( QPointF( 60,30 ), 5, 5 ) // Eye oPainter:drawEllipse( QPointF( 60,30 ), 1, 1 ) // Eye center oPainter:drawEllipse( QPointF( 50,50 ), 5, 15 ) // Nose oPainter:drawLine( 30, 70, 70, 75 ) // Mouth oPainter:end()

oLabel := QLabel( oWnd ) oLabel:setPixmap( oPixmap ) oLabel:move( 100, 20 )

oWnd:show() QApplication():exec()

RETURN

QPainter - Moving a faceThe following example shows how to draw and move a face with buttons. This sourceuses the class QPainter.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

127 de 195 13/02/2013 18:56

Page 128: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oLabel LOCAL oPixmap LOCAL oPainter LOCAL oButtonLeft, oButtonRight

oWnd := QWidget() oWnd:resize( 300, 200 ) oWnd:setWindowTitle( "Finestra di Giovanni" )

oPixmap := QPixmap( 100, 100 ) oPixmap:fill( QColor( 255,255,150 ) )

oPainter := QPainter( oPixmap ) oPainter:drawEllipse( QPointF( 50,50 ), 40, 40 ) // Face oPainter:drawEllipse( QPointF( 40,30 ), 5, 5 ) // Eye oPainter:drawEllipse( QPointF( 40,30 ), 1, 1 ) // Eye center oPainter:drawEllipse( QPointF( 60,30 ), 5, 5 ) // Eye oPainter:drawEllipse( QPointF( 60,30 ), 1, 1 ) // Eye center oPainter:drawEllipse( QPointF( 50,50 ), 5, 15 ) // Nose oPainter:drawLine( 30, 70, 70, 75 ) // Mouth oPainter:end()

oLabel := QLabel( oWnd ) oLabel:setPixmap( oPixmap ) oLabel:move( 100, 20 )

oButtonLeft := QPushButton( oWnd ) oButtonLeft:setText( "Left" ) oButtonLeft:move( 30, 160 ) oButtonLeft:Connect( "clicked()", { || MoveLeft( oLabel ) } ) oButtonRight := QPushButton( oWnd ) oButtonRight:setText( "Right" ) oButtonRight:move( 200, 160 ) oButtonRight:Connect( "clicked()", { || MoveRight( oLabel ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE MoveLeft( oL )

oL:move( oL:x() - 5, 20 )

RETURN

PROCEDURE MoveRight( oL )

oL:move( oL:x() + 5, 20 )

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

128 de 195 13/02/2013 18:56

Page 129: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QPainter - Saving a pictureThe following example shows how to save a picture to BMP and PNG files. The picture isnot visible on the screen.

PROCEDURE Main()

LOCAL oWnd LOCAL oPixmap LOCAL oPainter LOCAL k, oLabel

oWnd := QWidget() oWnd:resize( 250, 100 ) oWnd:setWindowTitle( "Finestra di Giovanni" )

oPixmap := QPixmap( 300, 200 ) oPixmap:fill( QColor( 200,255,255 ) )

oPainter := QPainter( oPixmap )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

129 de 195 13/02/2013 18:56

Page 130: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oPainter:drawLine( 30, 70, 70, 75 ) oPainter:drawLine( 10, 10, 70, 33 ) for k := 50 TO 250 STEP 10 oPainter:drawLine( k, 50, k, 150 ) next k

oPixmap:save( "sample.bmp" ) oPixmap:save( "sample.png" )

oLabel := QLabel( oWnd ) oLabel:setText( "BMP, PNG, Saved" ) oLabel:move( 20, 20 ) oLabel:resize( 200, 100 )

oWnd:show() QApplication():exec()

RETURN

QTreeView - The Tree of directories and foldersThe following example shows how to create a tree of the directories of your storagemedia. When you click on a file or folder, its name is shown in a text label.

PROCEDURE Main()

LOCAL oWnd, oModello, oAlbero, oText

oWnd := QMainWindow() oWnd:setWindowTitle( "Tree Directories" ) oWnd:setfixedsize( 800, 460 )

oModello := QFileSystemModel() oModello:setRootPath( "" )

oAlbero := QTreeView( oWnd ) oAlbero:resize( 780, 400 ) oAlbero:move( 10, 10 ) oAlbero:setIndentation( 20 ) oAlbero:setModel( oModello ) oAlbero:setSortingEnabled( .T. ) oAlbero:sortByColumn( 0, 0 ) oAlbero:setColumnWidth( 0, 300 ) oAlbero:setColumnWidth( 1, 100 ) oAlbero:setColumnWidth( 2, 100 ) oAlbero:setColumnWidth( 3, 100 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

130 de 195 13/02/2013 18:56

Page 131: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oAlbero:connect( "clicked(QModelIndex)", { |i| oText:setText( oModello:filePath( i ) ) } )

oText := QLabel( oWnd ) oText:setStyleSheet( "background-color: yellow; color: red;" ) oText:setText( "" ) oText:move( 10, 420 ) oText:resize( 780, 30 )

oWnd:show()

QApplication():exec()

RETURN

QResource - How to use ResourcesThe following example shows how to use the resource files. You can use images andcompile them in the executable file, so you can distribuite the exe file, without theimages. You need, for this example, the following files:

elektrosoft.prgelektrosoft.hbpelektrosoft.qrclogo.png

This is the file elektrosoft.hbp:

-w3hbqt.hbcelektrosoft.prgelektrosoft.qrc

This is the file elektrosoft.qrc:

<!DOCTYPE RCC><RCC version="1.0"><qresource prefix="/"> <file>logo.png</file></qresource></RCC>

Please rename correctly the files and the name of variables.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

131 de 195 13/02/2013 18:56

Page 132: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oLogo LOCAL oRes

oRes := QResource() oRes:registerResource_1( HBQTRES_ELEKTROSOFT() )

oWnd := QWidget() oWnd:SetFixedSize( 600, 300 ) oWnd:setStyleSheet( "background:#545A7C;" )

oLogo := QLabel( oWnd ) oLogo:move( 100, 60 ) oLogo:resize( 400, 181 ) oLogo:SetPixmap( QPixmap( ":logo.png" ) )

oWnd:show() QApplication():exec()

oRes:unregisterResource_1( HBQTRES_ELEKTROSOFT() )

RETURN

QScrollArea - Very simple scrolling areaThe following example shows how to create a simple scrolling area. The area can containany object. In this example, the label contains an image and the scroll area contains thelabel. The image is composed of 1200x860 pixels (in this example). You can scroll theimage using scrolling bars.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

132 de 195 13/02/2013 18:56

Page 133: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oImage LOCAL oArea

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 640, 480 )

oImage := QLabel( ) oImage:SetPixmap( QPixmap( "background.png" ) )

oArea := QScrollArea( oWnd ) oArea:move( 20, 20 ) oArea:resize( 600, 440 ) oArea:setWidget( oImage )

oWnd:show() QApplication():exec()

RETURN

QDialog - A modal window (1)This example shows how to create a modal window, using the "setmodal()" and "show()"functions.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

133 de 195 13/02/2013 18:56

Page 134: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oButton LOCAL oModal, oPassword

oWnd := QMainWindow() oWnd:SetFixedSize( 400, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oButton := QPushButton( oWnd ) oButton:setText( "Enter password" ) oButton:move( 100, 50 ) oButton:resize( 150, 30 ) oButton:Connect( "clicked()", {|| oModal:show() } )

// ----------------------------- oModal := QDialog() oModal:SetFixedSize( 300, 200 ) oModal:setWindowTitle( "Modal Window" ) oModal:setModal ( .T. )

oPassword := QLineEdit( oModal ) oPassword:move( 20, 50 )

oWnd:show() QApplication():exec()

RETURN

QDialog - A modal window (2)This example shows how to create a modal window, using only the "exec()" slot.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

134 de 195 13/02/2013 18:56

Page 135: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oButton LOCAL oModal, oPassword

oWnd := QMainWindow() oWnd:SetFixedSize( 400, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oButton := QPushButton( oWnd ) oButton:setText( "Enter password" ) oButton:move( 100, 50 ) oButton:resize( 150, 30 ) oButton:Connect( "clicked()", {|| oModal:exec() } )

// ----------------------------- oModal := QDialog() oModal:SetFixedSize( 300, 200 ) oModal:setWindowTitle( "Modal Window" )

oPassword := QLineEdit( oModal ) oPassword:move( 20, 50 )

oWnd:show() QApplication():exec()

RETURN

QToolBar - A simple textual Tool BarThis example shows how to create a simple Tool Bar, without icons. You can drag thetoolbar.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

135 de 195 13/02/2013 18:56

Page 136: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oQToolBar

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 200 )

oQToolBar := QToolBar ( oWnd ) oQToolBar:resize( 380, 30 ) oQToolBar:move( 0, 0 ) oQToolBar:addAction ( "New" ) oQToolBar:addAction ( "Open" ) oQToolBar:addAction ( "Save" ) oQToolBar:addAction ( "Cut" ) oQToolBar:addAction ( "Copy" ) oQToolBar:addAction ( "Paste" ) oQToolBar:addAction ( "Print" )

oWnd:show() QApplication():exec()

RETURN

QToolBar - A simple textual Tool Bar with separatorThis example shows how to create a simple Toolbar, without icons. The toolbar has aseparator.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

136 de 195 13/02/2013 18:56

Page 137: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oQToolBar

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 200 )

oQToolBar := QToolBar ( oWnd ) oQToolBar:resize( 200, 30 ) oQToolBar:move( 0, 0 ) oQToolBar:addAction ( "Large" ) oQToolBar:addSeparator () oQToolBar:addAction ( "Small" )

oWnd:show() QApplication():exec()

RETURN

QToolBar - A toolbar with icons, actions and tooltipsThis example has a toolbar with two icons. Pressing them, the main windows changes itssize. The actions have a tooltip.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

137 de 195 13/02/2013 18:56

Page 138: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oQToolBar, oAction1, oAction2

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 200 )

oQToolBar := QToolBar ( oWnd ) oQToolBar:resize( 100, 30 ) oQToolBar:move( 0, 0 )

oAction1 := QAction( oWnd ) oAction1:setIcon( QIcon( "small.png" ) ) oAction1:setToolTip( "Small" ) oAction1:connect( "triggered(bool)", {|| oWnd:resize( 100, 60 ) } )

oAction2 := QAction( oWnd ) oAction2:setIcon( QIcon( "large.png" ) ) oAction2:setToolTip( "Large" ) oAction2:connect( "triggered(bool)", {|| oWnd:resize( 400, 200 ) } )

oQToolBar:addAction( oAction1 ) oQToolBar:addAction( oAction2 )

oWnd:show() QApplication():exec()

RETURN

QToolBar - Draggable toolbarThis example shows how to create a draggable toolbar.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

138 de 195 13/02/2013 18:56

Page 139: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oQToolBar

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 200 )

oQToolBar := oWnd:addToolbar( "Toolbar" ) oQToolBar:resize( 380, 30 ) oQToolBar:move( 0, 0 ) oQToolBar:addAction ( "New" ) oQToolBar:addAction ( "Open" ) oQToolBar:addAction ( "Save" ) oQToolBar:addAction ( "Cut" ) oQToolBar:addAction ( "Copy" ) oQToolBar:addAction ( "Paste" ) oQToolBar:addAction ( "Print" ) oQToolBar:setFloatable( .T. ) oQToolBar:setMovable( .T. ) oWnd:show() QApplication():exec()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

139 de 195 13/02/2013 18:56

Page 140: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QFileDialog - Very simple File DialogThis example shows how to create a very simple File Dialog.

PROCEDURE Main()

LOCAL oFD

oFD := QFileDialog() oFD:show()

QApplication():exec()

RETURN

QFileDialog - A viewer for text filesThis example shows how to create a viewer for text files. User can choose the folder andthe file. It will be shown on the screen.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

140 de 195 13/02/2013 18:56

Page 141: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oButton, oEditor

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 700, 500 )

oEditor := QTextEdit( oWnd ) oEditor:resize( 600, 400 ) oEditor:move( 50, 50 )

oButton := QPushButton( oWnd ) oButton:setText( "Select a file" ) oButton:move( 10, 10 ) oButton:Connect( "clicked()", {|| viewFile( oEditor ) } )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

141 de 195 13/02/2013 18:56

Page 142: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:show() QApplication():exec()

RETURN

PROCEDURE viewFile( oEditor )

LOCAL oFileDialog, cListOfFiles, cFileName, cBuffer

oFileDialog := QFileDialog() oFileDialog:exec() cListOfFiles := oFileDialog:selectedFiles() cFileName := cListOfFiles:At( 0 ) cBuffer := MemoRead( cFileName ) oEditor:setText( cBuffer )

RETURN

QFileDialog - A viewer for BMP and PNGThis example shows how to create a viewer of BMP and PNG images. User can choosethe folder and the file. It will be shown on the screen.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

142 de 195 13/02/2013 18:56

Page 143: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oButton, oImg

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

143 de 195 13/02/2013 18:56

Page 144: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:resize( 200, 250 )

oImg := QLabel( oWnd ) oImg:move( 50, 50 ) oImg:resize( 100, 150 ) oImg:setStyleSheet( "border: 2px solid #0000ff;" )

oButton := QPushButton( oWnd ) oButton:setText( "Select a file" ) oButton:move( 10, 10 ) oButton:Connect( "clicked()", {|| viewImage( oImg ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE viewImage( oImg )

LOCAL oFileDialog, cListOfFiles, cFileName

oFileDialog := QFileDialog() oFileDialog:exec() cListOfFiles := oFileDialog:selectedFiles() cFileName := cListOfFiles:At( 0 ) oImg:SetPixmap( QPixmap( cFileName ) )

RETURN

QCheckBox - Simple checkboxesThis example shows how to create checkboxes.

PROCEDURE Main()

LOCAL oWnd LOCAL oCb1, oCb2

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oCb1 := QCheckBox ( oWnd ) oCb1:move( 20, 20 ) oCb1:setText( "First" )

oCb2 := QCheckBox ( oWnd ) oCb2:move( 20, 40 ) oCb2:setText( "Second" )

oWnd:show() QApplication():exec()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

144 de 195 13/02/2013 18:56

Page 145: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QCheckBox - Exclusive checkboxesThis example shows how to create exclusive checkboxes.

PROCEDURE Main()

LOCAL oWnd LOCAL oCb1, oCb2

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oCb1 := QCheckBox ( oWnd ) oCb1:move( 20, 20 ) oCb1:setText( "First" ) oCb1:setAutoExclusive ( .T. )

oCb2 := QCheckBox ( oWnd ) oCb2:move( 20, 40 ) oCb2:setText( "Second" ) oCb2:setAutoExclusive ( .T. )

oWnd:show() QApplication():exec()

RETURN

QCheckBox - How to set a checkboxThis example shows how to set a checkbox.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

145 de 195 13/02/2013 18:56

Page 146: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oCb1

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 300, 200 )

oCb1 := QCheckBox ( oWnd ) oCb1:move( 20, 20 ) oCb1:setText( "First" ) oCb1:setChecked ( .T. )

oWnd:show() QApplication():exec()

RETURN

QSAY, QGET, QREAD and friends - Input formYou can use new classes QSAY, QGET and QREAD to build an entry form in a similar-Clipper language. This forms accepts string data.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 )

@ 02, 05 Qsay "First: " Qget cOne @ 03, 05 Qsay "Second:" Qget cTwo @ 04, 05 Qsay "Third: " Qget cThree @ 05, 05 Qsay "Fourth:" Qget cFour QREAD

QApplication():exec()

RETURN NIL

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

146 de 195 13/02/2013 18:56

Page 147: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QSAY, QGET, QREAD and friends - Input formYou can use new classes QSAY, QGET and QREAD to build an entry form in a similar-Clipper language. This forms accepts numerical and string data. The dimension of theform depends from the position of the controls.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL nWidth, nHeight, nColor LOCAL SAYLIST := {} LOCAL GETLIST := {}

nWidth := 0 nHeight := 0 nColor := "Red "

@ 02, 05 Qsay "Width: " Qget nWidth @ 03, 05 Qsay "Heigth:" Qget nHeight @ 06, 30 Qsay "Color: " Qget nColor QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - Input formYou can use new classes QSAY, QGET and QREAD to build an entry form in a similar-Clipper language. This forms accepts numerical data.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

147 de 195 13/02/2013 18:56

Page 148: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL nWidth, nHeight LOCAL SAYLIST := {} LOCAL GETLIST := {}

nWidth := 0 nHeight := 0

@ 02, 05 Qsay "Width: " Qget nWidth @ 03, 05 Qsay "Heigth:" Qget nHeight QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - Input form with PICTUREYou can use new classes QSAY, QGET and QREAD to build an entry form in a similar-Clipper language. This forms accepts numerical data. The GETs clauses use PICTUREmask.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL nWidth, nHeight LOCAL SAYLIST := {} LOCAL GETLIST := {}

nWidth := 0 nHeight := 0

@ 02, 05 Qsay "Width: " Qget nWidth PICTURE "9999" @ 03, 05 Qsay "Heigth:" Qget nHeight PICTURE "999" QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - How to change the title barYou can change the title bar using the TITLE of QREAD.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

148 de 195 13/02/2013 18:56

Page 149: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL nWidth, nHeight LOCAL SAYLIST := {} LOCAL GETLIST := {}

nWidth := 0 nHeight := 0

@ 02, 05 Qsay "Width: " Qget nWidth @ 03, 05 Qsay "Heigth:" Qget nHeight QREAD TITLE "Giovanni's Window"

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - How to change the title barYou can change the title bar using the PROPERTIES of QREAD.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL nWidth, nHeight, nColor LOCAL SAYLIST := {} LOCAL GETLIST := {}

nWidth := 0 nHeight := 0 nColor := "Red "

@ 02, 05 Qsay "Width: " Qget nWidth @ 03, 05 Qsay "Heigth:" Qget nHeight @ 04, 05 Qsay "Color: " Qget nColor

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

149 de 195 13/02/2013 18:56

Page 150: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QREAD PROPERTIES {| oWnd| oWnd:setWindowTitle( "Just a Test" ) }

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - Colored GETsYou can change the color of the GET like Clipper language.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 )

@ 02, 05 Qsay "First: " Qget cOne COLOR "g+/b" @ 03, 05 Qsay "Second:" Qget cTwo COLOR "b+/r" @ 04, 05 Qsay "Third: " Qget cThree COLOR "w+/n" @ 05, 05 Qsay "Fourth:" Qget cFour COLOR "n/w" QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - Push ButtonThis code shows how to create a push button.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

150 de 195 13/02/2013 18:56

Page 151: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL lSave LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 ) lSave := .F.

@ 02, 05 Qsay "First: " Qget cOne @ 03, 05 Qsay "Second:" Qget cTwo @ 04, 05 Qsay "Third: " Qget cThree @ 05, 05 Qsay "Fourth:" Qget cFour @ 07, 10, 08, 20 QGET lSave PUSHBUTTON "Save" QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - CheckboxThis code shows how to create a Checkbox.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

151 de 195 13/02/2013 18:56

Page 152: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL lUpdated, lActive LOCAL SAYLIST := {} LOCAL GETLIST := {}

lUpdated := .F. lActive := .T.

@ 02, 05 QSAY "Updated?" @ 02, 20 QGET lUpdated CHECKBOX

@ 04, 05 QSAY "Active?" @ 04, 20 QGET lActive CHECKBOX QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - Display a textThis code shows how to display a text, using SAY clause.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL SAYLIST := {} LOCAL GETLIST := {}

@ 02, 05 QSAY "Text created by GIOVANNI DI MARIA" QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - ValidThis code shows how to validate the input fields.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

152 de 195 13/02/2013 18:56

Page 153: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL nWidth, nHeight, nColor LOCAL SAYLIST := {} LOCAL GETLIST := {}

nWidth := 5 nHeight := 0 nColor := "Red "

@ 02, 05 Qsay "Width: " Qget nWidth VALID nWidth >= 5 .AND. nWidth <= 10 @ 03, 05 Qsay "Heigth:" Qget nHeight @ 06, 30 Qsay "Color: " Qget nColor QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - WhenThis code shows how to input a field for a specific condition.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

153 de 195 13/02/2013 18:56

Page 154: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 )

@ 02, 05 Qsay "First: " Qget cOne @ 03, 05 Qsay "Second:" Qget cTwo WHEN AllTrim( Upper( cOne ) ) == "DI MARIA" @ 04, 05 Qsay "Third: " Qget cThree @ 05, 05 Qsay "Fourth:" Qget cFour QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - MemoeditThis code shows how to edit a text string in a "memo" field.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := "This tutorial is a brief of the use of the classes QT with Harbour language."

@ 01, 05 Qsay "First: " Qget cOne @ 02, 05 Qsay "Second:" Qget cTwo @ 03, 05 Qsay "Third: " Qget cThree @ 05, 05 Qsay "Fourth:" @ 05, 15, 09, 50 Qget cFour MEMOEDIT QREAD

QApplication():exec()

RETURN NIL

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

154 de 195 13/02/2013 18:56

Page 155: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QSAY, QGET, QREAD and friends - Many colorsThis code shows how to use many colors in the GET clause, with the function RGB.

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 )

@ 02, 05 Qsay "First: " Qget cOne COLOR "w+/rgb(250,0,0)" @ 03, 05 Qsay "Second:" Qget cTwo COLOR "w+/rgb(200,0,0)" @ 04, 05 Qsay "Third: " Qget cThree COLOR "w+/rgb(150,0,0)" @ 05, 05 Qsay "Fourth:" Qget cFour COLOR "w+/rgb(100,0,0)" QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - ListboxThis code shows how to implement a listbox as field.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

155 de 195 13/02/2013 18:56

Page 156: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL aList LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 ) aList := { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" }

@ 01, 05 Qsay "First: " Qget cOne @ 02, 05 Qsay "Second:" Qget cTwo @ 03, 05 Qsay "Third: " Qget cThree @ 05, 05 Qsay "Fourth:" @ 05, 15, 11, 30 Qget cFour LISTBOX aList QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - ComboboxThis code shows how to implement a combobox as field.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

156 de 195 13/02/2013 18:56

Page 157: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL aList LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 ) aList := { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" }

@ 01, 05 Qsay "First: " Qget cOne @ 02, 05 Qsay "Second:" Qget cTwo @ 03, 05 Qsay "Third: " Qget cThree @ 05, 05 Qsay "Fourth:" @ 05, 15, 5, 30 Qget cFour COMBOBOX aList QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - SetfocusThis code sets the focus to Fourth field if you press the button "Focus".

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

157 de 195 13/02/2013 18:56

Page 158: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL lSave LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 ) lSave := .F.

@ 02, 05 Qsay "First: " Qget cOne @ 03, 05 Qsay "Second:" Qget cTwo @ 04, 05 Qsay "Third: " Qget cThree @ 05, 05 Qsay "Fourth:" Qget cFour @ 07, 10, 08, 20 QGET lSave PUSHBUTTON "Focus" ACTION {|| GETLIST[ 4 ]:setFocus() } QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - Changing a fieldThis code assigns the value "Giovanni" to Fourth field if you press the button "Assign".

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

158 de 195 13/02/2013 18:56

Page 159: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL cOne, cTwo, cThree, cFour LOCAL lSave LOCAL SAYLIST := {} LOCAL GETLIST := {}

cOne := Space( 10 ) cTwo := Space( 10 ) cThree := Space( 10 ) cFour := Space( 10 ) lSave := .F.

@ 02, 05 Qsay "First: " Qget cOne @ 03, 05 Qsay "Second:" Qget cTwo @ 04, 05 Qsay "Third: " Qget cThree @ 05, 05 Qsay "Fourth:" Qget cFour @ 07, 10, 08, 20 QGET lSave PUSHBUTTON "Assign" ACTION {|| GETLIST[ 4 ]:setData( "Giovanni" ) } QREAD

QApplication():exec()

RETURN NIL

QSAY, QGET, QREAD and friends - Area of rectangle (accessing directly toGETLIST array)This code calculates the area of a rectangle when you press the button "Calculate".

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

159 de 195 13/02/2013 18:56

Page 160: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL nBase, nHeight, nArea LOCAL lButton LOCAL SAYLIST := {} LOCAL GETLIST := {}

nBase := 0 nHeight := 0 nArea := 0

@ 02, 05 Qsay "Base: " Qget nBase @ 03, 05 Qsay "Height: " Qget nHeight @ 05, 05 Qsay "Area: " Qget nArea

@ 07, 07, 08, 23 QGET lButton PUSHBUTTON "Calculate Area" ACTION {|| calculate( GETLIST ) } QREAD

QApplication():exec()

RETURN NIL

FUNCTION calculate( GETLIST )

LOCAL nBase2, nHeight2, nArea2

nBase2 := GETLIST[ 1 ]:getData() nHeight2 := GETLIST[ 2 ]:getData() nArea2 := nBase2 * nHeight2 GETLIST[ 3 ]:setData( nArea2 )

RETURN NIL

QSAY, QGET, QREAD and friends - Area of rectangle (accessing to GETLIST by"name" of variable)This code calculates the area of a rectangle when you press the button "Calculate".

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

160 de 195 13/02/2013 18:56

Page 161: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtstd.ch"

FUNCTION Main()

LOCAL nBase, nHeight, nArea LOCAL lButton LOCAL SAYLIST := {} LOCAL GETLIST := {}

nBase := 0 nHeight := 0 nArea := 0

@ 02, 05 Qsay "Base: " Qget nBase @ 03, 05 Qsay "Height: " Qget nHeight @ 05, 05 Qsay "Area: " Qget nArea

@ 07, 07, 08, 23 QGET lButton PUSHBUTTON "Calculate Area" ACTION {|| calculate( GETLIST ) } QREAD

QApplication():exec()

RETURN NIL

FUNCTION calculate( GETLIST )

LOCAL nBase2, nHeight2, nArea2 LOCAL nIndexBase, nIndexHeight, nIndexArea

// Searching the index of the variables nIndexBase := AScan( GETLIST, {| a| a:name() == "nBase" } ) nIndexHeight := AScan( GETLIST, {| a| a:name() == "nHeight" } ) nIndexArea := AScan( GETLIST, {| a| a:name() == "nArea" } )

// Taking value from fiels of the form nBase2 := GETLIST[ nIndexBase ]:getData() nHeight2 := GETLIST[ nIndexHeight ]:getData()

// Calculating area nArea2 := nBase2 * nHeight2 GETLIST[ nIndexArea ]:setData( nArea2 )

RETURN NIL

Games - Game of Colors

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

161 de 195 13/02/2013 18:56

Page 162: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

This is a game where the player must find the exact color randomly chosen by computer.The color is chosen by three slider of the RGB colors (red, green, blue). Player can getan hint from the computer. The maximum score is 765. Have fun.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oButtonStart, oButtonCheck, oButtonHint LOCAL oLcd LOCAL oTextMan, oTextPC LOCAL oRed, oGreen, oBlu LOCAL nRndRed, nRndGreen, nRndBlu

oWnd := QMainWindow() oWnd:resize( 400, 650 ) oWnd:setWindowTitle( "Giovanni" )

oButtonStart := QPushButton( oWnd ) oButtonStart:setText( "New Game" ) oButtonStart:move( 50, 30 ) oButtonStart:resize( 300, 50 ) oButtonStart:Connect( "clicked()", { || newgame( oLcd, oTextPC, oRed, oGreen, oBlu, @nRndRed, @nRndGreen, @nRndB

oTextPC := QLabel( oWnd ) oTextPC:setText( "Computer" ) oTextPC:move( 50, 80 ) oTextPC:resize( 300, 100 ) oTextPC:setFont( QFont( "Arial",46 ) ) oTextPC:setAlignment( Qt_AlignVCenter + Qt_AlignHCenter )

oTextMan := QLabel( oWnd ) oTextMan:setText( "You" ) oTextMan:move( 50, 160 ) oTextMan:resize( 300, 100 ) oTextMan:setFont( QFont( "Arial",46 ) ) oTextMan:setAlignment( Qt_AlignVCenter + Qt_AlignHCenter )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

162 de 195 13/02/2013 18:56

Page 163: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oRed := QSlider( oWnd ) oRed:resize( 40, 200 ) oRed:move( 120, 260 ) oRed:setMinimum( 0 ) oRed:setMaximum( 255 ) oRed:setSingleStep( 1 ) oRed:setPageStep( 10 ) oRed:setValue( 0 ) oRed:Connect( "valueChanged(int)", { || change_colors( oTextMan, oRed, oGreen, oBlu ) } )

oGreen := QSlider( oWnd ) oGreen:resize( 40, 200 ) oGreen:move( 180, 260 ) oGreen:setMinimum( 0 ) oGreen:setMaximum( 255 ) oGreen:setSingleStep( 1 ) oGreen:setPageStep( 10 ) oGreen:setValue( 0 ) oGreen:Connect( "valueChanged(int)", { || change_colors( oTextMan, oRed, oGreen, oBlu ) } )

oBlu := QSlider( oWnd ) oBlu:resize( 40, 200 ) oBlu:move( 240, 260 ) oBlu:setMinimum( 0 ) oBlu:setMaximum( 255 ) oBlu:setSingleStep( 1 ) oBlu:setPageStep( 10 ) oBlu:setValue( 0 ) oBlu:Connect( "valueChanged(int)", { || change_colors( oTextMan, oRed, oGreen, oBlu ) } )

oButtonCheck := QPushButton( oWnd ) oButtonCheck:setText( "Check your score (Max is 765)" ) oButtonCheck:move( 150, 500 ) oButtonCheck:resize( 200, 50 ) oButtonCheck:Connect( "clicked()", { || score( oLcd, oRed, oGreen, oBlu, nRndRed, nRndGreen, nRndBlu ) } )

oButtonHint := QPushButton( oWnd ) oButtonHint:setText( "Hint" ) oButtonHint:move( 50, 500 ) oButtonHint:resize( 90, 50 ) oButtonHint:Connect( "clicked()", { || hint( oRed, oGreen, oBlu, nRndRed, nRndGreen, nRndBlu ) } )

oLcd := QLCDNumber( oWnd ) oLcd:move( 150, 570 ) oLcd:resize( 200, 50 ) newgame( oLcd, oTextPC, oRed, oGreen, oBlu, @nRndRed, @nRndGreen, @nRndBlu ) // First time oWnd:show() QApplication():exec()

RETURN

PROCEDURE change_colors( oT , oR, oG, oB )

LOCAL oPalette

oPalette := QPalette() oPalette:SetColor( QPalette_WindowText, QColor( oR:value() ,oG:value() , oB:value() ) ) oT:setPalette( oPalette )

RETURN

PROCEDURE newgame( oLc, oTp , oR, oG, oB, nRndRed, nRndGreen, nRndBlu )

LOCAL oPalette

oR:setValue( 0 ) oG:setValue( 0 ) oB:setValue( 0 ) oLc:display( 0 )

nRndRed := hb_RandomInt( 0, 255 ) nRndGreen := hb_RandomInt( 0, 255 ) nRndBlu := hb_RandomInt( 0, 255 )

oPalette := QPalette() oPalette:SetColor( QPalette_WindowText, QColor( nRndRed , nRndGreen , nRndBlu ) ) oTp:setPalette( oPalette )

RETURN

PROCEDURE score( oL , oR, oG, oB, nRndRed, nRndGreen, nRndBlu )

LOCAL nScore

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

163 de 195 13/02/2013 18:56

Page 164: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

nScore := Abs( nRndRed - oR:value() ) + Abs( nRndGreen - oG:value() ) + Abs( nRndBlu - oB:value() ) nScore := 765 - nScore oL:display( nScore )

RETURN

PROCEDURE hint( oR, oG, oB, nRndRed, nRndGreen, nRndBlu )

oR:setValue( nRndRed ) oG:setValue( nRndGreen ) oB:setValue( nRndBlu )

RETURN

Games - Game of the Dog and the Cat (with boxes)This is a nice game where the player is a dog (the red square). The dog must take thecat (the blue square). Every time that the dog takes the cat, the score increments itsvalue by 1. The dog is moved by pressing arrow keys. Have fun.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oDog, oCat LOCAL oScore

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 ) oWnd:connect( QEvent_KeyPress , { |k| keypressed( k, oDog, oCat, oScore ) } )

oCat := QLabel( oWnd ) oCat:resize( 20, 20 ) oCat:move( 0, 0 ) oCat:setStyleSheet( "background-color: #0000FF" )

oDog := QLabel( oWnd ) oDog:resize( 30, 30 ) oDog:move( 150, 250 ) oDog:setStyleSheet( "background-color: #FF0000" )

oScore := QLCDNumber( oWnd ) oScore:resize( 100, 40 ) oScore:move( 250, 10 ) oScore:display( 0 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

164 de 195 13/02/2013 18:56

Page 165: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:show() QApplication():exec()

RETURN

PROCEDURE keypressed( x, oDog, oCat, oScore )

LOCAL nStep := 4 LOCAL nXdiff, nYdiff

//--------------------Keys---------------- DO CASE CASE x:key() == Qt_Key_Left oDog:move( oDog:x() - nStep , oDog:y() ) CASE x:key() == Qt_Key_Right oDog:move( oDog:x() + nStep , oDog:y() ) CASE x:key() == Qt_Key_Up oDog:move( oDog:x() , oDog:y() - nStep ) CASE x:key() == Qt_Key_Down oDog:move( oDog:x() , oDog:y() + nStep ) ENDCASE

//----------------Check for collision---------------- nXdiff := Abs ( oDog:x() - oCat:x() ) nYdiff := Abs ( oDog:y() - oCat:y() ) IF nXdiff < 10 .AND. nYdiff < 10 oCat:move( HB_RandomInt( 0, 380 ), HB_RandomInt( 60, 280 ) ) oScore:display( oScore:value() + 1 ) ENDIF

RETURN

Games - Game of the Dog and the Cat (with images)This is a nice game where the player is a dog. The dog must take the cat. Every time thatthe dog takes the cat, the score increments its value by 1. The dog and the cat are realbitmap images. The dog is moved by pressing arrow keys. Have fun.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oDog, oCat LOCAL oScore

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

165 de 195 13/02/2013 18:56

Page 166: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:connect( QEvent_KeyPress , { |k| keypressed( k, oDog, oCat, oScore ) } )

oCat := QLabel( oWnd ) oCat:resize( 20, 20 ) oCat:move( 0, 0 ) oCat:SetPixmap( QPixmap( "cat.bmp" ) )

oDog := QLabel( oWnd ) oDog:resize( 30, 30 ) oDog:move( 150, 250 ) oDog:SetPixmap( QPixmap( "dog.bmp" ) )

oScore := QLCDNumber( oWnd ) oScore:resize( 100, 40 ) oScore:move( 250, 10 ) oScore:display( 0 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE keypressed( x, oDog, oCat, oScore )

LOCAL nStep := 4 LOCAL nXdiff, nYdiff

//--------------------Keys---------------- DO CASE CASE x:key() == Qt_Key_Left oDog:move( oDog:x() - nStep , oDog:y() ) CASE x:key() == Qt_Key_Right oDog:move( oDog:x() + nStep , oDog:y() ) CASE x:key() == Qt_Key_Up oDog:move( oDog:x() , oDog:y() - nStep ) CASE x:key() == Qt_Key_Down oDog:move( oDog:x() , oDog:y() + nStep ) ENDCASE

//----------------Check for collision---------------- nXdiff := Abs ( oDog:x() - oCat:x() ) nYdiff := Abs ( oDog:y() - oCat:y() ) IF nXdiff < 10 .AND. nYdiff < 10 oCat:move( HB_RandomInt( 0, 380 ), HB_RandomInt( 60, 280 ) ) oScore:display( oScore:value() + 1 ) ENDIF

RETURN

Games - Game of the Dog and the Cat (with images and sound)This is a nice game where the player is a dog. The dog must take the cat. Every time thatthe dog takes the cat, the score increments its value by 1 and the cat meows. The dogand the cat are real bitmap images. The dog is moved by pressing arrow keys. Have fun.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

166 de 195 13/02/2013 18:56

Page 167: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oDog, oCat LOCAL oScore

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 ) oWnd:connect( QEvent_KeyPress , { |k| keypressed( k, oDog, oCat, oScore ) } )

oCat := QLabel( oWnd ) oCat:resize( 20, 20 ) oCat:move( 0, 0 ) oCat:SetPixmap( QPixmap( "cat.bmp" ) )

oDog := QLabel( oWnd ) oDog:resize( 30, 30 ) oDog:move( 150, 250 ) oDog:SetPixmap( QPixmap( "dog.bmp" ) )

oScore := QLCDNumber( oWnd ) oScore:resize( 100, 40 ) oScore:move( 250, 10 ) oScore:display( 0 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE keypressed( x, oDog, oCat, oScore )

LOCAL nStep := 4 LOCAL nXdiff, nYdiff

//--------------------Keys---------------- DO CASE CASE x:key() == Qt_Key_Left oDog:move( oDog:x() - nStep , oDog:y() ) CASE x:key() == Qt_Key_Right oDog:move( oDog:x() + nStep , oDog:y() ) CASE x:key() == Qt_Key_Up oDog:move( oDog:x() , oDog:y() - nStep ) CASE x:key() == Qt_Key_Down oDog:move( oDog:x() , oDog:y() + nStep ) ENDCASE

//----------------Check for collision---------------- nXdiff := Abs ( oDog:x() - oCat:x() ) nYdiff := Abs ( oDog:y() - oCat:y() ) IF nXdiff < 10 .AND. nYdiff < 10 oCat:move( HB_RandomInt( 0, 380 ), HB_RandomInt( 60, 280 ) ) oScore:display( oScore:value() + 1 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

167 de 195 13/02/2013 18:56

Page 168: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

QSound( "cat.wav" ):play() ENDIF

RETURN

Games - Dice Game (1 die)This is a nice game where the player play with one die.

PROCEDURE Main() LOCAL oWnd LOCAL oDice LOCAL oButton

oWnd := QMainWindow() oWnd:SetFixedSize( 200, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oButton := QPushButton( oWnd ) oButton:resize( 100, 50 ) oButton:move( 50, 200 ) oButton:setText( "Play now" ) oButton:Connect( "clicked()", { ||dice( oDice ) } )

oDice := QLabel( oWnd ) oDice:move( 50, 50 ) oDice:resize( 100, 100 )

dice( oDice )

oWnd:show() QApplication():exec()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

168 de 195 13/02/2013 18:56

Page 169: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE dice( oD )

LOCAL cFileName[6] LOCAL nRandom

cFileName[1] := "dice1.png" cFileName[2] := "dice2.png" cFileName[3] := "dice3.png" cFileName[4] := "dice4.png" cFileName[5] := "dice5.png" cFileName[6] := "dice6.png"

nRandom := HB_RandomInt( 1, 6 ) oD:SetPixmap( QPixmap( cFileName[nRandom] ) )

RETURN

Games - Dice Game (6 dice)This is a nice game where the player play with six dice. The dice are stored in a vector.

PROCEDURE Main() LOCAL oWnd LOCAL aoDice[6], k LOCAL oButton

oWnd := QMainWindow() oWnd:SetFixedSize( 700, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oButton := QPushButton( oWnd ) oButton:resize( 400, 50 ) oButton:move( 150, 200 ) oButton:setText( "Play now" ) oButton:Connect( "clicked()", { ||dice( aoDice ) } )

FOR k := 1 TO 6 aoDice[k] := QLabel( oWnd ) aoDice[k]:move( k * 110 - 85, 50 ) aoDice[k]:resize( 100, 100 ) NEXT k

dice( aoDice ) // First time

oWnd:show() QApplication():exec()

RETURN

PROCEDURE dice( oD )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

169 de 195 13/02/2013 18:56

Page 170: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

LOCAL k LOCAL cFileName[6] LOCAL nRandom

cFileName[1] := "dice1.png" cFileName[2] := "dice2.png" cFileName[3] := "dice3.png" cFileName[4] := "dice4.png" cFileName[5] := "dice5.png" cFileName[6] := "dice6.png"

FOR k := 1 TO 6 nRandom := hb_RandomInt( 1, 6 ) oD[k]:SetPixmap( QPixmap( cFileName[nRandom] ) ) NEXT k

RETURN

Sample Applications - Difference between two datesThe following example calculates the difference betwee two dates. The user must typetwo dates and then press the Calculate button. The program shows the difference, indays.

PROCEDURE Main()

LOCAL oWnd LOCAL oText LOCAL oButtonCalculate LOCAL oEdit1, oEdit2, oEdit3

SET DATE ITALIAN oWnd := QMainWindow() oWnd:resize( 400, 300 ) oWnd:setWindowTitle( "Giovanni" )

oText := QLabel( oWnd ) oText:setText( "Difference between two dates" ) oText:move( 130, 20 ) oText:resize( 171, 16 )

oEdit1 := QLineEdit( oWnd ) oEdit1:resize( 113, 20 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

170 de 195 13/02/2013 18:56

Page 171: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oEdit1:move( 140, 100 )

oEdit2 := QLineEdit( oWnd ) oEdit2:resize( 113, 20 ) oEdit2:move( 140, 130 )

oEdit3 := QLineEdit( oWnd ) oEdit3:resize( 113, 20 ) oEdit3:move( 140, 180 )

oButtonCalculate := QPushButton( oWnd ) oButtonCalculate:resize( 75, 23 ) oButtonCalculate:move( 270, 180 ) oButtonCalculate:setText( "Calculate" ) oButtonCalculate:Connect( "clicked()", { || calculate( oEdit1, oEdit2, oEdit3 ) } ) oWnd:show() QApplication():exec()

RETURN

PROCEDURE calculate( oE1, oE2, oE3 )

LOCAL nDifference

nDifference := Abs( CToD( oE1:text() ) - CToD( oE2:text() ) ) oE3:setText( AllTrim( Str(nDifference ) ) )

RETURN

Sample Applications - Radio Simulation (Visual only)The following example simulates a simple radio receiver. It's visual only, of course. I uselabels to draw the window tuning and the cursor of sintony.

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oTuning LOCAL oWheelVolume LOCAL oPalette LOCAL oLabelTuning, oLabelVolume LOCAL oDisplayVolume LOCAL oDisplayTuning, oWheelTuning, oCursor

oPalette := QPalette() oPalette:SetColor( QPalette_Window, QColor( 210,221,236 ) )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

171 de 195 13/02/2013 18:56

Page 172: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd := QMainWindow() oWnd:resize( 500, 300 ) oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:setPalette( oPalette )

// ---------------TUNING PANEL-------------- oTuning := QLabel( oWnd ) oTuning:resize( 460, 100 ) oTuning:move( 20, 20 ) oTuning:setStyleSheet( "background-color: #333333; color: #FFFFFF; border: 1px solid #00FF00;" ) oTuning:setText( "88 - - 92 - - 96 - - 100 - - 104 - - 108" ) oTuning:setAlignment( Qt_AlignHCenter + Qt_AlignVCenter ) oTuning:setFont( QFont( "Arial",16 ) )

// ---------------TUNING-------------- oWheelTuning := QDial( oWnd ) oWheelTuning:move( 320, 140 ) oWheelTuning:resize( 150, 150 ) oWheelTuning:setMinimum( 88 ) oWheelTuning:setMaximum( 108 ) oWheelTuning:setSingleStep( 1 ) oWheelTuning:setWrapping( .F. ) oWheelTuning:Connect( "valueChanged(int)", { ||tuning_change( oDisplayTuning, oWheelTuning, oCursor ) } )

oLabelTuning := QLabel( oWnd ) oLabelTuning:resize( 46, 13 ) oLabelTuning:move( 380, 130 ) oLabelTuning:setPalette( oPalette ) oLabelTuning:setText( "Tuning" )

oDisplayTuning := QLCDNumber( oWnd ) oDisplayTuning:resize( 111, 41 ) oDisplayTuning:move( 230, 130 ) oDisplayTuning:display( 88 )

// ---------------VOLUME-------------- oWheelVolume := QDial( oWnd ) oWheelVolume:move( 39, 186 ) oWheelVolume:resize( 100, 100 ) oWheelVolume:setMinimum( 0 ) oWheelVolume:setMaximum( 10 ) oWheelVolume:setSingleStep( 1 ) oWheelVolume:setWrapping( .F. ) oWheelVolume:Connect( "valueChanged(int)", { || oDisplayVolume:display( oWheelVolume:value() ) } )

oLabelVolume := QLabel( oWnd ) oLabelVolume:resize( 46, 13 ) oLabelVolume:move( 74, 178 ) oLabelVolume:setPalette( oPalette ) oLabelVolume:setText( "volume" )

oDisplayVolume := QLCDNumber( oWnd ) oDisplayVolume:resize( 101, 31 ) oDisplayVolume:move( 40, 144 )

// ---------------CURSOR-------------- oCursor := QLabel( oWnd ) oCursor:resize( 4, 98 ) oCursor:move( 45, 21 ) oCursor:setStyleSheet( "background-color: #FF0000" )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE tuning_change( oD, oW, oC )

LOCAL oPosition

oPosition := oW:value() * 20 - 1715 oD:display( oW:value() ) oC:move( oPosition, 21 )

RETURN

Sample Applications - Area and perimeter of a rectangle

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

172 de 195 13/02/2013 18:56

Page 173: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

The following example calculates the area and the perimeter of a rectangle. Input dataare typed by user.

PROCEDURE Main()

LOCAL oWnd LOCAL oRectangle LOCAL oButton LOCAL oWidth, oHeigth LOCAL oArea, oPerimeter

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

oRectangle := QLabel( oWnd ) oRectangle:resize( 200, 100 ) oRectangle:move( 50, 50 ) oRectangle:setStyleSheet( "background-color : red;" )

oWidth := QLineEdit( oWnd ) oWidth:move( 100, 20 ) oWidth:resize( 100, 20 )

oHeigth := QLineEdit( oWnd ) oHeigth:move( 260, 90 ) oHeigth:resize( 100, 20 )

oButton := QPushButton( oWnd ) oButton:move( 50, 180 ) oButton:resize( 200, 30 ) oButton:setText( "Calculate area and perimeter" ) oButton:connect( "clicked()", { || formulas( oWidth, oHeigth, oArea, oPerimeter ) } )

oArea := QLineEdit( oWnd ) oArea:move( 50, 220 ) oArea:resize( 100, 20 )

oPerimeter := QLineEdit( oWnd ) oPerimeter:move( 50, 250 ) oPerimeter:resize( 100, 20 )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE formulas( oWi, oHe, oAr, oPe )

LOCAL nArea, nPerimeter

nArea := Val( oWi:text() ) * Val( oHe:text() )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

173 de 195 13/02/2013 18:56

Page 174: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

nPerimeter := ( Val( oWi:text() ) + Val( oHe:text() ) ) * 2 oAr:setText( AllTrim( Str(nArea ) ) ) oPe:setText( AllTrim( Str(nPerimeter ) ) )

RETURN

Sample Applications - AlarmThe following example shows how to create a simple programmable alarm.

PROCEDURE Main()

LOCAL oWnd LOCAL oClock LOCAL oText, oText2 LOCAL oSetting

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 250, 150 )

oText := QLabel( oWnd ) oText:setText( "clocking..." ) oText:move( 100, 100 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

174 de 195 13/02/2013 18:56

Page 175: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oSetting := QTimeEdit( oWnd ) oSetting:move( 100, 50 )

oText2 := QLabel( oWnd ) oText2:setText( "Alarm at" ) oText2:move( 40, 50 )

oClock := QTimer() oClock:Connect( "timeout()", { || tick( oText, oSetting ) } ) oClock:start( 1000 )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE tick( oT, oS )

LOCAL oSetTime, nSetHou, nSetMin, nSetSec LOCAL cCurTime, nCurHou, nCurMin, nCurSec LOCAL oBox

oT:setText( Time() )

oSetTime := oS:Time() nSetHou := oSetTime:hour() nSetMin := oSetTime:minute() nSetSec := oSetTime:second()

cCurTime := Time() nCurHou := Val( Left( cCurTime,2 ) ) nCurMin := Val( SubStr( cCurTime,4,2 ) ) nCurSec := Val( Right( cCurTime,2 ) )

IF nSetHou == nCurHou .AND. nSetMin == nCurMin .AND. nSetSec == nCurSec oBox := QMessageBox() oBox:setWindowTitle( "Alarm" ) oBox:setInformativeText( "It's " + cCurTime + " o'clock" ) oBox:exec() ENDIF

RETURN

Sample Applications - ResistorsThe following example shows a program to calculate the value of a resistor. It show alsothe colors of its bars.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

175 de 195 13/02/2013 18:56

Page 176: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oTerminals, oBody LOCAL oBand1, oBand2, oBand3 LOCAL oChoose1, oChoose2, oChoose3 LOCAL oValue

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 400, 300 )

//----- Draw Terminals------------- oTerminals := QLabel( oWnd ) oTerminals:resize( 360, 10 ) oTerminals:move( 20, 50 ) oTerminals:setStyleSheet( "background-color : #C8C8C8;" )

//----- Draw body of resistance ------------- oBody := QLabel( oWnd ) oBody:resize( 200, 60 ) oBody:move( 100, 25 ) oBody:setStyleSheet( "background-color : #DCCCBA;" )

//----- Draw BAND 1------------- oBand1 := QLabel( oWnd ) oBand1:resize( 20, 60 ) oBand1:move( 120, 25 ) oBand1:setStyleSheet( "background-color : #000000;" )

oChoose1 := QSpinBox( oWnd ) oChoose1:move( 120, 100 ) oChoose1:resize( 42, 20 ) oChoose1:setMinimum( 0 ) oChoose1:setMaximum( 9 ) oChoose1:Connect( "valueChanged(int)", { ||resistor( oChoose1, oChoose2, oChoose3, oBand1, oBand2, oBand3, oValu

//----- Draw BAND 2------------- oBand2 := QLabel( oWnd ) oBand2:resize( 20, 60 ) oBand2:move( 170, 25 )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

176 de 195 13/02/2013 18:56

Page 177: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oBand2:setStyleSheet( "background-color : #000000;" )

oChoose2 := QSpinBox( oWnd ) oChoose2:move( 170, 100 ) oChoose2:resize( 42, 20 ) oChoose2:setMinimum( 0 ) oChoose2:setMaximum( 9 ) oChoose2:Connect( "valueChanged(int)", { ||resistor( oChoose1, oChoose2, oChoose3, oBand1, oBand2, oBand3, oValu

//----- Draw BAND 3------------- oBand3 := QLabel( oWnd ) oBand3:resize( 20, 60 ) oBand3:move( 220, 25 ) oBand3:setStyleSheet( "background-color : #000000;" )

oChoose3 := QSpinBox( oWnd ) oChoose3:move( 220, 100 ) oChoose3:resize( 42, 20 ) oChoose3:setMinimum( 0 ) oChoose3:setMaximum( 9 ) oChoose3:Connect( "valueChanged(int)", { ||resistor( oChoose1, oChoose2, oChoose3, oBand1, oBand2, oBand3, oValu

//----- Resistor value------------- oValue := QLabel( oWnd ) oValue:resize( 350, 50 ) oValue:move( 25, 190 ) oValue:setStyleSheet( "background-color : #FFFFBB;" )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE resistor( oChoose1, oChoose2, oChoose3, oBand1, oBand2, oBand3, oValue )

LOCAL cColors[10] LOCAL nC1, nC2, nC3 LOCAL v

cColors[1] := "#000000" cColors[2] := "#836543" cColors[3] := "#FF0000" cColors[4] := "#FF9146" cColors[5] := "#FFFF00" cColors[6] := "#00FF00" cColors[7] := "#0000FF" cColors[8] := "#BF00BF" cColors[9] := "#C0C0C0" cColors[10] := "#FFFFFF"

nC1 := oChoose1:value() nC2 := oChoose2:value() nC3 := oChoose3:value()

oBand1:setStyleSheet( "background-color : " + cColors[nC1+1] + ";" ) oBand2:setStyleSheet( "background-color : " + cColors[nC2+1] + ";" ) oBand3:setStyleSheet( "background-color : " + cColors[nC3+1] + ";" )

v := Val( AllTrim( Str(nC1 ) ) + AllTrim( Str(nC2 ) ) ) v := Int( v * 10 ^ nC3 ) v := AllTrim( Str( v ) ) + " Ohms" v := "<font color=#000077 size=6>" + v + "</font>" v := "<center>" + v + "</center>"

oValue:setText( v )

RETURN

Sample Applications - AquariusThe following example shows how to create a virtual aquarius with fishes. The fishesmove from side to side. The fishes are in .PNG format image, with transparency.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

177 de 195 13/02/2013 18:56

Page 178: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oSea LOCAL oClock LOCAL oFish1, oFish2, oFish3, oFish4, oFish5

oWnd := QMainWindow() oWnd:SetFixedSize( 600, 400 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oClock := QTimer() oClock:Connect( "timeout()", { || moveFish( oFish1, oFish2, oFish3, oFish4, oFish5 ) } ) oClock:start( 50 )

oSea := QLabel( oWnd ) oSea:move( 0, 0 ) oSea:resize( 600, 400 ) oSea:SetPixmap( QPixmap( "aquarium1.bmp" ) )

oFish1 := QLabel( oWnd ) oFish1:move( 300, 110 ) oFish1:resize( 180, 180 ) oFish1:SetPixmap( QPixmap( "fish1.png" ) )

oFish2 := QLabel( oWnd ) oFish2:move( 200, 40 ) oFish2:resize( 150, 150 ) oFish2:SetPixmap( QPixmap( "fish2.png" ) )

oFish3 := QLabel( oWnd ) oFish3:move( 100, 320 ) oFish3:resize( 100, 50 ) oFish3:SetPixmap( QPixmap( "fish3.png" ) )

oFish4 := QLabel( oWnd ) oFish4:move( 300, 250 ) oFish4:resize( 150, 70 ) oFish4:SetPixmap( QPixmap( "fish4.png" ) )

oFish5 := QLabel( oWnd ) oFish5:move( 50, 10 ) oFish5:resize( 150, 70 ) oFish5:SetPixmap( QPixmap( "fish5.png" ) )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE moveFish( oF1, oF2, oF3, oF4, oF5 )

oF1:move( oF1:x - 1, oF1:y ) IF oF1:x <- 180

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

178 de 195 13/02/2013 18:56

Page 179: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oF1:move( 600, oF1:y ) end IF

oF2:move( oF2:x - 1.5, oF2:y ) IF oF2:x <- 150 oF2:move( 600, oF2:y ) end IF

oF3:move( oF3:x - 2, oF3:y ) IF oF3:x <- 100 oF3:move( 600, oF3:y ) end IF

oF4:move( oF4:x + 1.3 , oF4:y ) IF oF4:x > 600 oF4:move( - 150, oF4:y ) end IF

oF5:move( oF5:x + 1.5 , oF5:y ) IF oF5:x > 600 oF5:move( - 150, oF5:y ) end IF

RETURN

Sample Applications - Semaphore (automatic)The following example shows how to create an automatic semaphore. It changes its colorevery a second.

PROCEDURE Main()

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

179 de 195 13/02/2013 18:56

Page 180: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

LOCAL oWnd LOCAL oImg LOCAL oClock LOCAL nSequence

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 250, 450 )

oImg := QLabel( oWnd ) oImg:move( 25, 25 ) oImg:resize( 200, 400 )

nSequence := 1 semaphore( oImg, @nSequence ) // First time

oClock := QTimer() oClock:Connect( "timeout()", { || semaphore( oImg, @nSequence ) } ) oClock:start( 1000 )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE semaphore( oI, nSeq )

DO CASE CASE nSeq == 1 oI:SetPixmap( QPixmap( "semaforo1.png" ) ) CASE nSeq == 2 oI:SetPixmap( QPixmap( "semaforo2.png" ) ) CASE nSeq == 3 oI:SetPixmap( QPixmap( "semaforo3.png" ) ) ENDCASE nSeq ++ IF nSeq == 4 nSeq := 1 ENDIF

RETURN

Sample Applications - Semaphore (manual)The following example shows how to create a manual semaphore. It changes its color ifthe button is pressed.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

180 de 195 13/02/2013 18:56

Page 181: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oImg LOCAL oButton LOCAL nSequence

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) oWnd:resize( 250, 500 )

oImg := QLabel( oWnd ) oImg:move( 25, 25 ) oImg:resize( 200, 400 )

nSequence := 1 semaphore( oImg, @nSequence ) // First time

oButton := QPushButton ( oWnd ) oButton:move( 50, 430 ) oButton:resize( 150, 30 ) oButton:setText( "Press to change color" ) oButton:Connect( "clicked()", { || semaphore( oImg, @nSequence ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE semaphore( oI , nSeq )

DO CASE CASE nSeq == 1 oI:SetPixmap( QPixmap( "semaforo1.png" ) ) CASE nSeq == 2 oI:SetPixmap( QPixmap( "semaforo2.png" ) ) CASE nSeq == 3 oI:SetPixmap( QPixmap( "semaforo3.png" ) ) ENDCASE nSeq ++ IF nSeq == 4 nSeq := 1 ENDIF

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

181 de 195 13/02/2013 18:56

Page 182: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

Sample Applications - Scrolling titlesThe following example shows how to create scrolling titles, like movie titles. Them scrollup and shows some image, too.

PROCEDURE Main()

LOCAL oWnd LOCAL OWinBg LOCAL oClock LOCAL nVTitleSpace, nSpeed, sTxt LOCAL oStr1, oStr2, oStr3 LOCAL oImg1, oImg2

nVTitleSpace := 300 nSpeed := 2

oWnd := QMainWindow() oWnd:SetFixedSize( 600, 400 ) oWnd:setWindowTitle( "The end" )

oClock := QTimer() oClock:Connect( "timeout()", { || moveTitle( oClock, nSpeed, oStr1, oStr2, oStr3, oImg1, oImg2 ) } ) oClock:start( 50 )

OWinBg := QLabel( oWnd )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

182 de 195 13/02/2013 18:56

Page 183: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

OWinBg:move( 0, 0 ) OWinBg:resize( 600, 400 ) OWinBg:SetPixmap( QPixmap( "bra01-background.png" ) )

oImg1 := QLabel( oWnd ) oImg1:move( 10, nVTitleSpace ) oImg1:resize( 300, 300 ) oImg1:SetPixmap( QPixmap( "bra01-arbour.png" ) )

oImg2 := QLabel( oWnd ) oImg2:move( 310, nVTitleSpace ) oImg2:resize( 600, 300 ) oImg2:SetPixmap( QPixmap( "bra01-logo_qt.png" ) )

oStr1 := QLabel( oWnd ) oStr1:move( 10, nVTitleSpace ) oStr1:resize( 550, 60 ) oStr1:SetText( "<center><h3>Harbour and Qt</h3></center><br>" ) oStr1:setStylesheet( "background: gray; border: 2px dotted white; border-radius: 20px; background: transparent;

sTxt := "To see the code of this image and test scrolling little demo,<br>" sTxt += "please visit the tutorial site... there are a lot of other stuffs...<br>" sTxt += "<br>" sTxt += "http://www.gruppoeratostene.com/harbour/harbour-tutorials.htm<br>"

oStr2 := QLabel( oWnd ) oStr2:move( 10, nVTitleSpace * 2 ) oStr2:resize( 550, 140 ) oStr2:SetText( sTxt ) oStr2:setStylesheet( "font-size: 14px; color: white;" )

oStr3 := QLabel( oWnd ) oStr3:move( 10, nVTitleSpace * 3 ) oStr3:resize( 550, 140 ) oStr3:SetText( "<center> <h1>The End</h1><br><br>Special thank to Harbour and Qt<br>" + ; "www.harbour-project.org <br> qt.nokia.com" + ; "</center>" ) oStr3:setStylesheet( "font-size: 15px; color: white;" )

oWnd:show() QApplication():exec() oClock:stop()

RETURN

PROCEDURE moveTitle( oC, nS, oS1, oS2, oS3, oI1, oI2 )

oI1:move( oI1:x , oI1:y - nS ) oI2:move( oI2:x , oI2:y - nS ) oS1:move( oS1:x , oS1:y - nS ) oS2:move( oS2:x , oS2:y - nS )

IF oS3:y < 120 oC:stop() ENDIF

oS3:move( oS3:x, oS3:y - nS )

RETURN

Sample Applications - Televideo TeletextThe following example shows the page 101 of Italian Teletext Service (Televideo). Thispage shows last news in Italy and in the World. The program searches for a new pageevery 30 seconds.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

183 de 195 13/02/2013 18:56

Page 184: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd, oImg, oClock, nColpi

nColpi := 29

oWnd := QMainWindow() oWnd:SetFixedSize( 700, 500 ) oWnd:setStyleSheet( " background-color: #CCCCFF; " ) oWnd:setWindowTitle( "Giovanni" )

oImg := QLabel( oWnd ) oImg:move( 28, 50 ) oImg:resize( 644, 400 )

oClock := QTimer() oClock:Connect( "timeout()", {|| pUpdate( oWnd, oImg, @nColpi ) } ) oClock:start( 1000 )

pUpdate( oWnd, oImg, @nColpi ) oWnd:show() QApplication():exec()

RETURN

PROCEDURE pUpdate( oWnd, oImg, nColpi )

LOCAL oHttp, cString

oWnd:setWindowTitle( Time() )

nColpi++ IF nColpi == 30 nColpi := 0 oHttp := TIPClientHTTP():new( "http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-101.png" oHttp:open() cString := oHttp:readAll() oHttp:close() hb_MemoWrit( "televideo.png", cString ) oImg:SetPixmap( QPixmap( "televideo.png" ) ) ENDIF

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

184 de 195 13/02/2013 18:56

Page 185: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

Sample Applications with Databases - DBF Database Append RecordThe following example shows how to store data into a DBF database. Pressing the Savebutton, the data are saved into a DBF, thank to REPLACE command.

PROCEDURE Main()

LOCAL oWnd LOCAL oName, oLabel1 LOCAL oBorn, oLabel2 LOCAL oSons, oLabel3 LOCAL oButton

SET DATE ITALIAN SET CENTURY ON

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

185 de 195 13/02/2013 18:56

Page 186: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oWnd:resize( 400, 300 )

oLabel1 := QLabel( oWnd ) oLabel1:setText( "Name" ) oLabel1:move( 50, 50 ) oLabel1:resize( 100, 20 )

oName := QLineEdit( oWnd ) oName:move( 160, 50 ) oName:resize( 150, 20 )

oLabel2 := QLabel( oWnd ) oLabel2:setText( "Date of birth " ) oLabel2:move( 50, 80 ) oLabel2:resize( 100, 20 )

oBorn := QLineEdit( oWnd ) oBorn:move( 160, 80 ) oBorn:resize( 90, 20 )

oLabel3 := QLabel( oWnd ) oLabel3:setText( "Number of sons" ) oLabel3:move( 50, 110 ) oLabel3:resize( 100, 20 )

oSons := QLineEdit( oWnd ) oSons:move( 160, 110 ) oSons:resize( 50, 20 )

oButton := QPushButton( oWnd ) oButton:setText( "Save" ) oButton:move( 150, 200 ) oButton:Connect( "clicked()", { || store( oName,oBorn,oSons ) } )

oWnd:show() QApplication():exec()

RETURN

PROCEDURE STORE( oN, oB, oS )

USE sample APPEND BLANK REPLACE sample -> cognome WITH oN:text() REPLACE sample -> nascita WITH CToD( oB:text() ) REPLACE sample -> figli WITH Val( oS:text() ) USE

RETURN

Sample Applications with Databases - DBEdit simulationThe following example shows how to simulate the DbEdit function to browse a DBF. Thefields and records cannot be changed but only viewed.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

186 de 195 13/02/2013 18:56

Page 187: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

//------------Declaration-------------- LOCAL oWnd LOCAL oCell, valore LOCAL nNumField, nNumRecord, oLabels LOCAL nX, nY LOCAL button_top, button_bottom LOCAL oTable

oWnd := QMainWindow() oWnd:resize( 800, 600 ) oWnd:setWindowTitle( "DbEdit simulation" )

//------------Open DBF and count field and record------------ USE sample nNumRecord := RecCount() nNumField := FCount()

//------------Table-------------- oTable := QTableWidget( oWnd ) oTable:move( 50, 50 ) oTable:resize( 700, 450 ) oTable:setRowCount( nNumRecord ) oTable:setColumnCount( nNumField ) oTable:setColumnWidth( 0, 200 )

//------------Fill table-------------- for nX := 1 TO nNumRecord for nY := 1 TO nNumField oCell := QTableWidgetItem() valore := FieldGet( nY ) DO CASE CASE ValType( valore ) == "C" oCell:setText( valore ) CASE ValType( valore ) == "N" oCell:setText( AllTrim( Str(valore ) ) ) CASE ValType( valore ) == "D" oCell:setText( DToC( valore ) ) CASE ValType( valore ) == "L" oCell:setText( iif( valore == .T. ,"Yes","No" ) ) end CASE oTable:setItem( nX - 1, nY - 1, oCell )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

187 de 195 13/02/2013 18:56

Page 188: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

next nY SKIP next nX

//------------Label Table-------------- oLabels := QStringList() for nX := 1 TO 50 oLabels:append( field( nX ) ) next nX oTable:setHorizontalHeaderLabels( oLabels ) USE

//------------Button-------------- button_top := QPushButton( oWnd ) button_top :move( 100, 520 ) button_top:setText( "Top" ) button_top:Connect( "clicked()", { || top( oTable ) } )

button_bottom := QPushButton( oWnd ) button_bottom:move( 300, 520 ) button_bottom:setText( "Bottom" ) button_bottom:Connect( "clicked()", { || bottom( oTable ) } )

//------------Exec-------------- oWnd:show() QApplication():exec()

RETURN

PROCEDURE top( oT )

oT:scrollToTop() oT:setCurrentCell( 0, 0 ) oT:setFocus()

RETURN

PROCEDURE bottom( oT )

oT:scrollToBottom() oT:setCurrentCell( oT:rowCount() - 1, 0 ) oT:setFocus()

RETURN

Sample Applications with Databases - Flags and DatabaseThe following example shows flags on a form. The flags are stored in a DBF archive.User can browse data by the "prev" and "next" buttons.

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

188 de 195 13/02/2013 18:56

Page 189: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

PROCEDURE Main()

LOCAL oWnd LOCAL oPrev, oNext LOCAL oImg, oState

oWnd := QMainWindow() oWnd:SetFixedSize( 400, 300 ) oWnd:setWindowTitle( "Finestra Giovanni" )

oState := QLineEdit( oWnd ) oState:move( 100, 20 ) oState:resize( 200, 20 ) oState:setReadOnly( .T. )

oImg := QLabel( oWnd ) oImg:move( 50, 50 ) oImg:resize( 300, 200 ) oImg:setStyleSheet( "border: 2px solid #0000ff;" )

oPrev := QPushButton( oWnd ) oPrev:move( 50, 260 ) oPrev:setText( "Prev" ) oPrev:Connect( "clicked()", { || go_prev( oImg, oState ) } )

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

189 de 195 13/02/2013 18:56

Page 190: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

oNext := QPushButton( oWnd ) oNext:move( 250, 260 ) oNext:setText( "Next" ) oNext:Connect( "clicked()", { || go_next( oImg, oState ) } )

USE flags

first_time( oImg, oState ) oWnd:show() QApplication():exec()

USE

RETURN

PROCEDURE go_prev( oI, oS )

skip - 1 oS:setText( flags -> state ) oI:SetPixmap( QPixmap( AllTrim(flags -> flag ) ) )

RETURN

PROCEDURE go_next( oI, oS )

SKIP oS:setText( flags -> state ) oI:SetPixmap( QPixmap( AllTrim(flags -> flag ) ) )

RETURN

PROCEDURE first_time( oI, oS )

oS:setText( flags -> state ) oI:SetPixmap( QPixmap( AllTrim(flags -> flag ) ) )

RETURN

Sample Applications with Databases - Navigating in a DBFThe following example shows how to navigate in a DBF archive. User can browse databy the "prev" and "next" buttons. Some objects are STATIC to use them in externalfunctions.

STATIC oLineEdit1, oLineEdit2, oLineEdit3PROCEDURE Main()

LOCAL oWnd

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

190 de 195 13/02/2013 18:56

Page 191: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

LOCAL oLabel1, oLabel2, oLabel3 LOCAL oButton1, oButton2

oWnd := QMainWindow() oWnd:resize( 400, 300 )

USE archivio

// ---------------------------------LABELS oLabel1 := QLabel( oWnd ) oLabel1:setText( "Nombre" ) oLabel1:move( 5, 50 )

oLabel2 := QLabel( oWnd ) oLabel2:setText( "Apellido" ) oLabel2:move( 5, 100 )

oLabel3 := QLabel( oWnd ) oLabel3:setText( "Edad" ) oLabel3:move( 5, 150 )

// ---------------------------------FIELDS EDIT oLineEdit1 := QLineEdit( oWnd ) oLineEdit1:move( 60, 50 ) oLineEdit1:resize( 300, 20 )

oLineEdit2 := QLineEdit( oWnd ) oLineEdit2:move( 60, 100 ) oLineEdit2:resize( 300, 20 )

oLineEdit3 := QLineEdit( oWnd ) oLineEdit3:move( 60, 150 ) oLineEdit3:resize( 300, 20 )

// ---------------------------------BUTTONS oButton1 := QPushButton( oWnd ) oButton1:setText( "<" ) oButton1:move( 50, 200 ) oButton1:resize( 50, 50 ) oButton1:Connect( "clicked()", {|| fPrev() } )

oButton2 := QPushButton( oWnd ) oButton2:setText( ">" ) oButton2:move( 150, 200 ) oButton2:resize( 50, 50 ) oButton2:Connect( "clicked()", {|| fNext() } )

view() // It Shows the FIRST TIME

oWnd:show() QApplication():exec()

USE

RETURN// ---------------------------------------------PROCEDURE view()

oLineEdit1:setText( FIELD->nombre ) oLineEdit2:setText( FIELD->apellido ) oLineEdit3:setText( AllTrim( Str( FIELD->edad ) ) )

RETURN// ---------------------------------------------PROCEDURE fPrev()

SKIP -1 view()

RETURN// ---------------------------------------------PROCEDURE fNext()

SKIP view()

RETURN

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

191 de 195 13/02/2013 18:56

Page 192: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

Appendix A - Photos

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

192 de 195 13/02/2013 18:56

Page 193: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

193 de 195 13/02/2013 18:56

Page 194: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

Appendix B - Contributors

Giovanni Di Maria (he is still the main developer)Marco BraidaMassimo BelgranoMario Wan Stadnik (Qatan)ApolinarAleksander Czajczynski

Appendix C - What users think

Sounds good! (Viktor Szakats)Thanks again for your nice tutorial. (Viktor Szakats)It's very nice job, thanks for this tutorial. (Viktor Szakats)As said earlier it is a noble initiative and will stir a lot of enthusiam for Harbourusers. (Pritpal Bedi)Thanks for your great initiative providing that important tutorial. It is encouragingme to try HBQT and I found it is not as diffcult as I first thought. Thanks for yourhelp. Regards. (Qatan)Thank you Giovanni for the tutorial. (Guy Roussin)Complimenti Giovanni il tuo lavoro del quale riporto per comodita' il link diretto. E'utilissimo... grazie per la condivisione... (Marco Braida)Thanks a lot Giovanni! (Maurilio Longo)That said, I really appreciate your tutorial! (Maurilio Longo)I think your tutorial's link should be loaded on harbour's web page. (Angel Pais)Many thanks for your great work. (Shum)Congratulations for nice contribuition. (Itamar M. Lins Jr. Lins)Dear Giovanni: Thank you for the tutorial of hbqt. It is very useful for me. Bestregards. (Daniel Tello Argentina)Imo this tutorial is good also as offcial harbour doc. (Massimo Belgrano)It's great service for whole Harbour community. Well done and keep it up. Also agreat example for how to contribute. (Viktor Szakats)Hi Giovanni, magnificent tutorial. Many thanks. (Claudia Neumann)Hi. I am having fun with hbqt and understand most of the excellent tutorialexamples from Giovanni Di Maria. Thanks for that! I do however find the qt4documentation quite daunting and ask for some help/further examples to do withevents. (Charlesg)Thank you for your diligent effort on your tutorial on Harbour QT. Each example isvery easy to understand the way you present them. I have learned quite a lot fromthem and can envision how to utilize them. Once again I thank you for the tutorial.(Gabriel Zippilli - USA)Tnx, for your work. (Antonio Montagut)Hi Giovanni. Very good, your samples are the best "appetizers" for QTprogramming I've ever seen. (Viktor Szakats)FWQT tutorial is based on excellent Giovanni Di Maria's HBQT tutorial. (AntonioLinares)Your tutorial is really fantastic and invites to explore QT, thanks! :-). (AntonioLinares)Ya tengo el browse de mi .dbf, ahora a tunearlo a mi gusto, mil gracias, no hubiesepodido hacer mucho sin tu tutorial !!! (Fermín Barboza)Great tutorial! ;-)) (Patrick Mast)Excelente introduccion!... Gracias!! (Carlos Omran)Hello Giovanni. I just discovered your manual and I am immensely grateful for this,congratulations. Excellent contribution. Best Regards, Edgar San. (Edgar Lee)Many thanks for this tutorial. Cheers. (Luigi Ferraris)

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

194 de 195 13/02/2013 18:56

Page 195: HBQT - The Tutorial About Harbour and QT Programming - By Giovanni Di Maria

Appendix D - Communities

Facebook Group HbQtGoogle QtContribs GroupGoogle Harbour Developers Group

HBQT - The tutorial about Harbour and QT programming - by Giovanni ... http://www.elektrosoft.it/tutorials/hbqt/hbqt.asp

195 de 195 13/02/2013 18:56