hbqt tutorial 9 maio de 2011

40
Page 1 ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria 08/06/2012 03:27:17 http://www.elektrosoft.it/tutorials/hbqt.asp HBQT-Tutorial Giovanni Di Maria since: May 9, 2011 Harbour (3.1) and QT Classes (4.8) - Tutorial Rev. [1] February 12, 2011 - Rev. [4031] May 9, 2011 Record of Revision Revision Description 1 Feb 12, 2011 10 Feb 16, 2011 50 Feb 21, 2011 100 Feb 24, 2011 200 Feb 28, 2011 300 Mar 02, 2011 400 Mar 04, 2011 500 Mar 06, 2011 600 Mar 07, 2011 700 Mar 08, 2011 800 Mar 09, 2011 900 Mar 15, 2011 1000 Mar 22, 2011 1100 Mar 23, 2011 1200 Mar 24, 2011 1300 Mar 24, 2011 1400 Mar 30, 2011 1500 Mar 30, 2011 2000 Mar 30, 2011 2500 Mar 30, 2011 3000 Apr 03, 2011

Upload: drmicroso

Post on 28-Apr-2015

21 views

Category:

Documents


5 download

DESCRIPTION

Harbour programacao

TRANSCRIPT

Page 1: HBQT tutorial 9 maio de 2011

Page 1ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

HBQT-TutorialGiovanni Di Mariasince: May 9, 2011

Harbour (3.1) and QT Classes (4.8) - Tutorial

Rev. [1] February 12, 2011 - Rev. [4031] May 9, 2011

Record of Revision

Revision Description

1 Feb 12, 2011

10 Feb 16, 2011

50 Feb 21, 2011

100 Feb 24, 2011

200 Feb 28, 2011

300 Mar 02, 2011

400 Mar 04, 2011

500 Mar 06, 2011

600 Mar 07, 2011

700 Mar 08, 2011

800 Mar 09, 2011

900 Mar 15, 2011

1000 Mar 22, 2011

1100 Mar 23, 2011

1200 Mar 24, 2011

1300 Mar 24, 2011

1400 Mar 30, 2011

1500 Mar 30, 2011

2000 Mar 30, 2011

2500 Mar 30, 2011

3000 Apr 03, 2011

Page 2: HBQT tutorial 9 maio de 2011

Page 2ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

3500 Apr 18, 2011

4000 Apr 21, 2011

IntroductionThis tutorial is a brief, continuously updated, of the use of the classes QT with Harbour language.It is specifically written for beginners that initially encountered some difficulties in using theseclasses, however, extremely powerful and efficient. The approach of the tutorial is different fromother guides that are online. It simply focuses a single class or single object, so you do not getlost in the maze of the vast files of examples provided with the product. This will easily learn tomanage and plan their individual class, as needed, 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".The path of this include is (for windows) /hbnn/includeYou should consult the Nokia's offcial documentationIf possible, you must not use static variablesYou should disconnect the objects that were attached with the connect methodIt is strongly recommended to use hbformat tool to format the .prg sourcesTo create a source, you can copy and paste the code to your text editor and save it with.prg extension

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

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

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

sample.exelibgcc s dw2-1.dllmingwm10.dllQtCore4.dllQtGui4.dll

These DLLs are located in C:/hbnn/bin or in C:/hbnn/comp/mingw/bin.

QMainWindow - WindowThe following example shows how to create a simple main window. The window is resizable. (byGiovanni Di Maria)

Page 3: HBQT tutorial 9 maio de 2011

Page 3ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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. (by Giovanni Di Maria)

#include "hbqtgui.ch"

Page 4: HBQT tutorial 9 maio de 2011

Page 4ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

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 locked and theheight is resizable. (by Giovanni Di Maria)

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd

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

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

RETURN

QMainWindow - Window with Fixed heightThe following example shows how to create a simple main window. The height is locked and thewidth is resizable. (by Giovanni Di Maria)

Page 5: HBQT tutorial 9 maio de 2011

Page 5ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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. (by Giovanni Di Maria)

Page 6: HBQT tutorial 9 maio de 2011

Page 6ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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

Page 7: HBQT tutorial 9 maio de 2011

Page 7ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

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

#include "hbqtgui.ch"

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. (byGiovanni Di Maria)

#include "hbqtgui.ch"

Page 8: HBQT tutorial 9 maio de 2011

Page 8ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

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 )

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

RETURN

QMainWindow - Window with backgroundThe following example shows how to create a window with a background from an image. (byGiovanni Di Maria)

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd, oButton

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

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

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

RETURN

Page 9: HBQT tutorial 9 maio de 2011

Page 9ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

QWidget - Widgets in a Main WindowThe following example shows how to create some widgets in a main window. The widgetscontain buttons. If you have to move the buttons, simply move the widget only. The MainWindow is the parent of the widgets. The widgets are the parent of the buttons. (by Giovanni DiMaria)

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 )

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; " )

Page 10: HBQT tutorial 9 maio de 2011

Page 10ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

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

QApplication - BeepThe following example shows how to create a simple main window, as application. At exit, theapplication produces a beep. This method sounds the bell, using the default volume and sound.The function is not available in Qt for Embedded Linux. (by Giovanni Di Maria)

Page 11: HBQT tutorial 9 maio de 2011

Page 11ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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. (by Giovanni DiMaria)

Page 12: HBQT tutorial 9 maio de 2011

Page 12ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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. (by Apolinar)

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd

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

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

RETURN

// END SOURCE

Page 13: HBQT tutorial 9 maio de 2011

Page 13ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

QDateEdit - Editing a dateThe following example shows how to enter and edit a date. (by Giovanni Di Maria)

#include "hbqtgui.ch"

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

QTimeEdit - Editing the timeThe following example shows how to enter the time. (by Giovanni Di Maria)

Page 14: HBQT tutorial 9 maio de 2011

Page 14ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oSetting

oWnd := QMainWindow() oWnd:setWindowTitle( "Finestra di Giovanni" ) 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. (byGiovanni Di Maria)

Page 15: HBQT tutorial 9 maio de 2011

Page 15ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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 calendar.The buttons allow to navigate through the months and to show or hide the grid. (by Giovanni DiMaria)

Page 16: HBQT tutorial 9 maio de 2011

Page 16ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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

Page 17: HBQT tutorial 9 maio de 2011

Page 17ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

Qlabel - Text LabelThe following example shows how to create a simple main window with a label, used as textstring. (by Giovanni Di Maria)

#include "hbqtgui.ch"

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. (by Giovanni DiMaria)

Page 18: HBQT tutorial 9 maio de 2011

Page 18ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

PROCEDURE Main()

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( "../res/sample.bmp" ) ) 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 as textstring. The label is colored using QSS. (by Giovanni Di Maria)

Page 19: HBQT tutorial 9 maio de 2011

Page 19ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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 textstring. The label is colored using QPalette. (by Giovanni Di Maria)

Page 20: HBQT tutorial 9 maio de 2011

Page 20ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#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 as textstring. The label is colored and formatted using HTML. (by Giovanni Di Maria)

#include "hbqtgui.ch"

PROCEDURE Main()

LOCAL oWnd LOCAL oText LOCAL cString

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

Page 21: HBQT tutorial 9 maio de 2011

Page 21ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

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( 20, 20 ) oText:resize( 200, 150 )

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

RETURN

Qlabel - Circular LabelThe following example shows how to create a circular label. The label is colored and formattedusing QSS. (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()

Page 22: HBQT tutorial 9 maio de 2011

Page 22ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

RETURN

Qlabel - Horizontal lineThe following example shows how to simulate a horizontal line. A good solution is to create alabel with a thickness of 1 or 2 pixels. (by Giovanni Di Maria)

#include "hbqtgui.ch"

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 to create alabel with a thickness of 1 or 2 pixels. (by Giovanni Di Maria)

Page 23: HBQT tutorial 9 maio de 2011

Page 23ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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 create twoarrays of labels, with a thickness of 1 or 2 pixels. The first array is used for horizontal lines, thesecond array is used for vertical lines. (by Giovanni Di Maria)

Page 24: HBQT tutorial 9 maio de 2011

Page 24ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#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; color:red;" ) 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

Page 25: HBQT tutorial 9 maio de 2011

Page 25ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

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

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

RETURN

Qlabel - Modify the FramesThe following example shows how to change the frame of the labels. (by Giovanni Di Maria)

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

Page 26: HBQT tutorial 9 maio de 2011

Page 26ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

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

RETURN

Qlabel - AlignmentThe following example shows how to align a text in a QLabel. (by Giovanni Di Maria)

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

Page 27: HBQT tutorial 9 maio de 2011

Page 27ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

QApplication():exec()

RETURN

Qlabel - Setting a numberThe following example shows how to set a number in a QLabel, without the use of strings. (byGiovanni 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

// END SOURCE

QMessageBox - Message Box (simple)The following example shows how to create a simple window with an active button. If the buttonis pressed, a message box appears. (by Giovanni Di Maria)

Page 28: HBQT tutorial 9 maio de 2011

Page 28ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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!!! " ) 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 No button. If theYes button is pressed, the window title changes. (by Giovanni Di Maria)

Page 29: HBQT tutorial 9 maio de 2011

Page 29ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

STATIC oWnd

PROCEDURE Main()

LOCAL 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:show() QApplication():exec()

RETURN

PROCEDURE MsgYesNo()

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 )

Page 30: HBQT tutorial 9 maio de 2011

Page 30ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

nButtonPressed := oMB:exec()

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

RETURN

QPushButton - Simple buttonThe following example shows how to create a simple button. If pressed, the window will beresized. (by Giovanni Di Maria)

#include "hbqtgui.ch"

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 )

RETURN

Page 31: HBQT tutorial 9 maio de 2011

Page 31ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

QPushButton - Button with iconThe following example shows how to create a simple button with a icon. If pressed, the title barchanges. (by Giovanni Di Maria)

#include "hbqtgui.ch"

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.bmp" ) ) 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. If the firstbutton is pressed, the window closes. If the second button is pressed, the title of the windowchanges his value. (by Giovanni Di Maria)

Page 32: HBQT tutorial 9 maio de 2011

Page 32ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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( "../res/star_32.bmp" ) ) 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. (by Giovanni DiMaria)

Page 33: HBQT tutorial 9 maio de 2011

Page 33ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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

Page 34: HBQT tutorial 9 maio de 2011

Page 34ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

QPushButton - Array of Buttons with variable dimensionsThe following example shows how to create many buttons, stored in an array. Their dimension isset by an incremental variable. (by Giovanni Di Maria)

#include "hbqtgui.ch"

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

Page 35: HBQT tutorial 9 maio de 2011

Page 35ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

RETURN

QPushButton - Button TipsThe following example shows how to create a button with the tip. (by Giovanni Di Maria)

#include "hbqtgui.ch"

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. (by Giovanni Di Maria)

Page 36: HBQT tutorial 9 maio de 2011

Page 36ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

PROCEDURE Main()

LOCAL oButton1, oWnd

oWnd := QMainWindow() oWnd:setWindowTitle( "Giovanni" ) 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():play( "../res/cat.wav" )

RETURN

QStatusBar - Status BarThe following example shows how to create and modify the status bar, at the bottom of thewindow. (by Giovanni Di Maria)

Page 37: HBQT tutorial 9 maio de 2011

Page 37ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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. (by Giovanni Di Maria)

Page 38: HBQT tutorial 9 maio de 2011

Page 38ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

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 status bargoes to left and right. (by Giovanni Di Maria)

Page 39: HBQT tutorial 9 maio de 2011

Page 39ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

#include "hbqtgui.ch"

STATIC nSpaces := 1 STATIC nInc := 1 STATIC oSBar

PROCEDURE Main()

LOCAL oWnd LOCAL oClock

oWnd := QMainWindow()

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

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

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

oWnd:setStatusBar( oSBar )

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

RETURN

PROCEDURE pingpong()

LOCAL cString

cString = Space( nSpaces ) + "Hello" oSBar:showMessage( cString ) nSpaces += nInc

IF nSpaces = 40 nInc =- 1 ENDIF

IF nSpaces = 1 nInc = 1 ENDIF

Page 40: HBQT tutorial 9 maio de 2011

Page 40ElektroSoft - Elettronica ed Informatica - di Giovanni Di Maria

08/06/2012 03:27:17http://www.elektrosoft.it/tutorials/hbqt.asp

RETURN