Comand "DEFINE BKGBRUSH" in HMG.4

Moderator: Rathinagiri

Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by Ricci »

Another problem assigning a background image to the main window: placing stylesheed command in :OnInit() maybe too early.

Code: Select all

:OnInit := { || oWindow:Center(), oWindow:GraphLabel:qtObject:setStyleSheet( "background-image: url('hmg.png');" )  } 
did not work well. Only 640*480px are filled with the background.

Code: Select all

:OnSize:= { || oWindow:GraphLabel:qtObject:setStyleSheet( "background-image: url('hmg.png');" )  }
should solve the problem.
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by mrduck »

Ricci wrote:Another problem assigning a background image to the main window: placing stylesheed command in :OnInit() maybe too early.

Code: Select all

:OnInit := { || oWindow:Center(), oWindow:GraphLabel:qtObject:setStyleSheet( "background-image: url('hmg.png');" )  } 
did not work well. Only 640*480px are filled with the background.
Strange, since the window domensions are correctly set (otherwise :center would fail....)
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by l3whmg »

Ricci wrote:
l3whmg wrote: On the other hand, you and Rossine use this syntax "::oQTObject:setStyleSheet( csetStyleSheet )".
In this way previous and/or different style will be lost. Isn't it?
No, not the whole stylesheet is lost with setStyleSheet(). It works as in XHTML, you only change these parts of the whole (unknown) stylesheet that you like.
Are you sure? Many times ago, I write StyleUpdater() - public function within misc.prg - because with setStyleSheet() I lost previous style.....I'm doing another thing, can you do a simple test with one label? At defining time, you must use "LabelObjectName:setStyleSheet( cStyleCode ) " an then change something. Don't use HMG4 StyleSheet() method.

ie.

Code: Select all

WITH OBJECT oLabel = LABEL():New()
....
END WITH
oLabel:QtObject:setStyleSheet( "background-color: red" )
somewhere

Code: Select all

oLabel:QtObject:setStyleSheet( "color: yellow" )
You must see red as background color and yellow as font color.....
and then

Code: Select all

oLabel:QtObject:setStyleSheet( "background-color: green" )
You must see green as background color and yellow as font color.....
Ricci wrote:I would prefer the first way by directly changing styles in program code (in OnInit() or later) than defining a lot of methods for that in the basic class. There maybe a hundred of style commands, impossible to write a method for each.
I think/understand you write about Qtobject:setStyleSheet( something ) in other word (if work fine) oHmgObject:StyleSheet( something ). I understand?
Luigi from Italy
www.L3W.it
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by l3whmg »

Hi friends.

with setStyleSheet() on M$XP it's a caos....but I try this solution and seems work fine :)

Code: Select all

   LOCAL cBackGround := hb_fnameMerge( ImagesPath, ImageName )
   LOCAL oQtPalette  := QPalette()

   oQtPalette:setBrush( HmgMainForm:QtObject:backgroundRole(), QBrush( QImage( cBackGround ) ) )
   HmgMainForm:QtObject:setPalette( oQtPalette )
You can insert these lines within your OnInit function. You must change HmgMainForm with your HMG4 object and adjust "ImagesPath" and "ImageName".

If ImageName size is less then QtObject size it will repeat.
Don't overlap Menu but I don't check other objects.

You can also try "HmgMainForm:QtParent...." instead "HmgMainForm:QtObject...."

Cheers
Luigi from Italy
www.L3W.it
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by Ricci »

l3whmg wrote:
Ricci wrote:I would prefer the first way by directly changing styles in program code (in OnInit() or later) than defining a lot of methods for that in the basic class. There maybe a hundred of style commands, impossible to write a method for each.
I think/understand you write about Qtobject:setStyleSheet( something ) in other word (if work fine) oHmgObject:StyleSheet( something ). I understand?
That would be great !
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by Ricci »

l3whmg wrote:
Ricci wrote:
No, not the whole stylesheet is lost with setStyleSheet(). It works as in XHTML, you only change these parts of the whole (unknown) stylesheet that you like.
Are you sure?
I think I found out how it works: not identical to XHTML.

Every Qt-application has an application-wide style sheet (that can be changed).
If you overwrite something (i.e. a Label) with oMainform:oLabel:QtObject:setStyleSheet( "background-color: red; color: yellow;" ) than the text will be yellow on red background.
If you do a second oMainform:oLabel:QtObject:setStyleSheet( "background-color: green;" ) on this label than first all user defined definitions are deleted (back to application-wide style sheet) and than the new stylesheet command will be executed. At the end you get black text on green background.

So you need to save your old definition before applying the new one:
oMainform:oLabel:QtObject:setStyleSheet( "background-color: red; color: yellow;" )
oMainform:oLabel:QtObject:setStyleSheet( oMainform:oLabel:QtObject:StyleSheet( ) + "background-color: green;" )
This will give you a yellow text on green background.
You have two times a background-color in you style-sheet command (first red, second green) but as the CSS rules say: the last one wins. ;)
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by l3whmg »

Hi Ricci.
Ricci wrote:I think I found out how it works: not identical to XHTML.
Every Qt-application has an application-wide style sheet (that can be changed).
If you overwrite something (i.e. a Label) with oMainform:oLabel:QtObject:setStyleSheet( "background-color: red; color: yellow;" ) than the text will be yellow on red background.
If you do a second oMainform:oLabel:QtObject:setStyleSheet( "background-color: green;" ) on this label than first all user defined definitions are deleted (back to application-wide style sheet) and than the new stylesheet command will be executed. At the end you get black text on green background.
Now you have done my experience ;)
Ricci wrote:So you need to save your old definition before applying the new one:
oMainform:oLabel:QtObject:setStyleSheet( "background-color: red; color: yellow;" )
oMainform:oLabel:QtObject:setStyleSheet( oMainform:oLabel:QtObject:StyleSheet( ) + "background-color: green;" )
This will give you a yellow text on green background.
You have two times a background-color in you style-sheet command (first red, second green) but as the CSS rules say: the last one wins
But why you don't use StyleSheet() Hmg4 method? If it doesn't work you can do changes. Please take a look into misc.prg to the related function. I write this function, but every one can improve it :D
Luigi from Italy
www.L3W.it
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by mrduck »

It is possible to set CSS for each object, you have to name it in the CSS.

But there is something that is not clear...
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by Ricci »

l3whmg wrote:Hi Ricci.
But why you don't use StyleSheet() Hmg4 method? If it doesn't work you can do changes. Please take a look into misc.prg to the related function. I write this function, but every one can improve it :D
As you wrote in misc.prg: "Problem: if there is a style with double ":" it fails (ie "background-image: url('http://www.mysite.com/paper.gif');")"
Grafics that are linked into the program won´t work too ( ie "background-image: url(':mypicture');" )

You don´t have to replace a style command with the new one (what can cause problems with the ':'), adding it to the old stylesheet is enough in CSS.
This will work without problems: ;)

Code: Select all

FUNCTION StyleUpdater( cOldStyle, cNewStyle )

   LOCAL cUpdateStyle

   IF VALTYPE( cOldStyle ) == "C"
         cUpdateStyle := cOldStyle + cNewStyle
   ELSE
      cUpdateStyle := cNewStyle
   ENDIF

   IF RIGHT( cUpdateStyle, 1 ) <> ";"
      cUpdateStyle += ";"
   ENDIF

RETURN cUpdateStyle
Rossine
Posts: 87
Joined: Thu Jun 30, 2011 10:04 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by Rossine »

Hello All,

I solved this with method resize():

Code: Select all

...
:Onsize := { || RESIZE_IMG() }
...
      DEFINE IMAGE Image2
          ROW        0
          COL        0
          WIDTH      0
          HEIGHT     0
          PICTURE    "image.bmp"
          STRETCH    .F.
      END IMAGE
...



**************************      
static function RESIZE_IMG
**************************

cWndForm:Image2:ScaledToWidth  := .T.
cWndForm:Image2:ScaledToHeight := .T.
cWndForm:Image2:row    := 71
cWndForm:Image2:col    := 0
cWndForm:Image2:Width  := cWndForm:Width
cWndForm:Image2:Height := cWndForm:Height-220

return NIL
This worked fine ;)

Thanks for the attention of all,

Rossine.
Post Reply