Widget Style

Moderator: Rathinagiri

Post Reply
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Has thanked: 3 times
Been thanked: 7 times
Contact:

Widget Style

Post by pctoledo » Tue Aug 02, 2011 7:48 pm

Hi Friends, Qt's support for widget styles and themes enables your application to fit in with the native desktop enviroment. I modified the file hmgapp.prg to set the styles:

File: globshared.prg

Code: Select all

   CLASS VAR s_cStyle                  INIT  NIL      SHARED
File: hmgapp.prg

Code: Select all

   METHOD Style                        SETGET

Code: Select all

METHOD Style( cStyle ) CLASS HMGAPP

   IF PCOUNT() == 0
      RETURN ::s_cStyle
   ELSEIF ::s_lQtStarted == .F. .AND.  hb_IsChar( cStyle ) == .T.
      ::s_cStyle := cStyle
   ENDIF

RETURN Self

Code: Select all

METHOD Reset() CLASS HMGAPP

   ::s_oQtApp           := NIL
   ::s_oQtRes           := NIL
   ::s_aResources       := {}
   ::s_oDefaultParent   := NIL
   ::s_nObjectCounter   := 0
   ::s_oMainWindow      := NIL
   ::s_lGridCellFlag    := .F.
   ::s_oMainMenu        := NIL
   ::s_oParentWindow    := NIL
   ::s_cNewPopUpMenuName:= NIL
   ::s_cNewMenuItemName := NIL

   ::s_nCountry         := NIL
   ::s_oCurWindow       := NIL
   ::s_nLanguage        := NIL
   ::s_bOnShutDown      := NIL
   ::s_bOnStartUp       := NIL
   ::s_cPlugInDir       := NIL
   ::s_oQtLocale        := NIL
   ::s_lQtStarted       := .F.
   ::s_oTopParent       := NIL
   ::s_cStyle           := NIL

RETURN Self

Code: Select all

METHOD Start() CLASS HMGAPP

   LOCAL cPath, cFile, cExt, nX, cResFileName

   // check if it's already started
   IF ::s_lQtStarted == .T.
      RETURN Self
   ENDIF

   // split program name for two reason
   // 1. to have the current path
   // 2. to have the program name and register default resource with program name
   hb_fNameSplit( hb_ProgName(), @cPath, @cFile, @cExt )

   ::s_lQtStarted := .T.
   ::s_oQtApp     := QApplication()
   ::s_oQtRes     := QResource()

   // localization
   IF VALTYPE( ::s_nLanguage ) == "U"
      ::s_oQtLocale     := QLocale()
      ::s_oQtLocale:setDefault( QLocale() )
   ELSEIF VALTYPE( ::s_nLanguage ) == "N"
      IF VALTYPE( ::s_nCountry ) == "U" ; ::s_nCountry := 0 ; ENDIF     // 0 is like QLocale_AnyCountry
      ::s_oQtLocale     := QLocale( ::s_nLanguage, ::s_nCountry )
      ::s_oQtLocale:setDefault( QLocale( ::s_nLanguage, ::s_nCountry ) )
   ENDIF

   // if ::s_cPlugInDir not evaluated create a default <exePath\Qt\plugins>. If qt.conf exists take that
   IF VALTYPE( ::s_cPlugInDir ) == "U"
      ::s_cPlugInDir := cPath + "Qt" + hb_ps() + "plugins"
   ENDIF
   ::s_oQtApp:addLibraryPath( ::s_cPlugInDir )

   ::s_oDefaultParent   := Self
   ::s_oTopParent       := Self
   ::oQtObject          := ::s_oQtApp:DeskTop()

   // by default register resource file with the same name of program (see harbour)
   Self:RegisterResource( cFile )
   FOR nX := 1 TO LEN( ::s_aResources )
      cResFileName := ::s_aResources[nX]
      IF TYPE( cResFileName ) == "UI"  // to find if exist this function
         ::s_oQtRes:registerResource_1( &cResFileName )
      ENDIF
   NEXT nX

   // Set Widget Style
   IF VALTYPE( ::s_cStyle ) == "C"
      ::s_oQtApp:SetStyle( ::s_cStyle )
   ENDIF

   //    check OnStartUp
   IF hb_IsBlock( ::s_bOnStartUp ) == .T.
      EVAL( ::s_bOnStartUp )
   ENDIF

RETURN Self
Example use:

Code: Select all

FUNCTION Main

   LOCAL oWindow

   HbQt_ErrorSys()

   HMGAPP():Style( "cleanlooks" )

   WITH OBJECT oWindow := Window():New()
      :Row      := 10
      :Col      := 10
      :Width    := 400
      :Height   := 400
      :Title    := 'Widget Styles'
      :Type     := WND_MAIN
      :OnInit   := { || oWindow:Center() }
   END WITH

   oWindow:Activate()

   RETURN NIL
Supported styles:
cleanlooks
plastique
motif
CDE
windows
windowsxp
windowsvista
macintosh
GTK

Sample:
Image
Attachments
style.zip
File Samples
(3.54 KiB) Downloaded 79 times
Regards/Saludos,

Toledo

Clipper On Line

User avatar
Rathinagiri
Posts: 5263
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Wed Aug 03, 2011 2:55 am

This is so nice.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Wed Aug 03, 2011 9:10 am

Many thanks. Very nice.
Luigi from Italy
www.L3W.it

mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Post by mrduck » Wed Aug 03, 2011 10:26 am

pctoledo wrote:Hi Friends, Qt's support for widget styles and themes enables your application to fit in with the native desktop enviroment.
Patch committed to svn, please check

User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Has thanked: 3 times
Been thanked: 7 times
Contact:

Post by pctoledo » Wed Aug 03, 2011 11:19 am

mrduck, all ok!

Thanks for the help.
Regards/Saludos,

Toledo

Clipper On Line

Post Reply