Comand "DEFINE BKGBRUSH" in HMG.4

Moderator: Rathinagiri

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

Comand "DEFINE BKGBRUSH" in HMG.4

Post by Rossine »

Hello,

There hmg.4 this command in one or another way of putting a background image in a window?

DEFINE BKGBRUSH newBrush DEFINE WINDOW PATTERN IN BITMAP Form_1 ping.bmp nodelete

Best Regards,

Rossine.
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 Rossine.
At this moment you can use :StyleSheet := "....." to assign a background image to the mainform.
You must enter value as CSS property (ie "background-image:url('paper.gif'").
This technique can affect the subsequent widgets backgrounds, so be careful.
In addition, the use of style sheets must be used carefully.
Please, do some test before and report here your impressions.

Many thanks
Luigi from Italy
www.L3W.it
Rossine
Posts: 87
Joined: Thu Jun 30, 2011 10:04 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by Rossine »

Hello Luigi,

It would be possible to include this code in hmg.4 ?

Hello Luigi,


Sample Using Brush:

Code: Select all


/*
 * $Id: demo_1.prg 760 2011-10-21 12:01:51Z l3wonsf $
*/

/*
 * HMG 4 demo
 * (c) 2010 Roberto Lopez <mail.box.hmg@gmail.com>
*/

#include "hmg.ch"

FUNCTION Main

   LOCAL oWindow

   HbQt_ErrorSys()

   WITH OBJECT oWindow := MAINWINDOW():New()
      :Row    := 10
      :Col    := 10
      :Width  := 400
      :Height := 400
      :Title  := 'Nice OOP Demo!!!'
      :OnInit := { || oWindow:Center() }
      :Brush  := "hmg.png"

   END WITH

   oWindow:Activate()

   RETURN NIL

Code for BASIC.PRG:

Code: Select all


CLASS BASIC FROM GLOBSHARED, HMGPARENT

...
   DATA cBrush                                    INIT   ""                PROTECTED

...


   METHOD Brush( cValue ) SETGET


...

/*..............................................................................*/

   METHOD Brush( cValue ) CLASS BASIC

   local csetStyleSheet := ""
   
   IF Pcount() == 0
      RETURN ""
   ELSEIF Pcount() == 1
      IF ValType( cValue ) == 'C'
         ::cBrush := strtran( cValue, "\", "/" )
         csetStyleSheet += "border-image: url('" + ::cBrush + "');"
         ::oQTObject:setStyleSheet( csetStyleSheet )
      ENDIF
   ENDIF

   RETURN ""

Please correct me if some code was wrong ok ? ;)

Many Thank´s,

Rossine.

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

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by Rossine »

Hello Luigi,

The problem is that all objects inherit the property "brush". You know how to do only "window" to use the property "brush" ?

Best Regards,

Rossine.
Attachments
brush.png
brush.png (639.26 KiB) Viewed 4517 times
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by Ricci »

Rossine, to assign a brush only to your window background use this:

Code: Select all

WITH OBJECT oWindow := MAINWINDOW():New()
      :Row    := 10
      :Col    := 10
      :Width  := 400
      :Height := 400
      :Title  := 'Nice OOP Demo!!!'
      :OnInit := { || oWindow:Center(), oWindow:GraphLabel:qtObject:setStyleSheet( "border-image: url('hmg.png');" )  }
or with your enhancement of the basic class:

Code: Select all

WITH OBJECT oWindow := MAINWINDOW():New()
      :Row    := 10
      :Col    := 10
      :Width  := 400
      :Height := 400
      :Title  := 'Nice OOP Demo!!!'
      :OnInit := { || oWindow:Center(), oWindow:GraphLabel:Brush("hmg.png") }
This code is a little bit better:

Code: Select all

/*..............................................................................
   Brush
..............................................................................*/
   METHOD Brush( cValue ) CLASS BASIC

   IF Pcount() == 0
      RETURN ::cBrush
   ELSEIF Pcount() == 1
      IF ValType( cValue ) == 'C'
         ::cBrush := strtran( cValue, "\", "/" )
         ::oQTObject:setStyleSheet( "border-image: url('" + ::cBrush + "');" )
      ENDIF
   ENDIF

   RETURN NIL
Last edited by Ricci on Thu Nov 03, 2011 9:22 am, edited 3 times in total.
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: Comand "DEFINE BKGBRUSH" in HMG.4

Post by mrduck »

Rossine,
in Qt CSS we may specify the objects we want the css be applied to using "meta-names" like QLabel or "proper" name of objects like "form1" but Qt must be informed about the object name.
Please open Qt Assistant and search for "stylesheet", there are some infos.

It seems strange to me that the background image is applied on each object...

Sorry I don't have much time in these days
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 Rossine.
Hi Rossine.
Yes it's possible, but IMHO usage of stylesheet, with customized commands, it can open problems.
Your example is fine, but please take a while to thinks about many users: someone want border, someone doesn't want, someone customize dimensions, etc. If I create a method like BackImage or BkBrush I have only one possibility: customizing the style sheet within command. But next time, someone wants a little different style and so on. I don't know.

I hope that my English and my explanation is clear :mrgreen:

On the other hand, as I write to you, the usage of stylesheet can create problem as you shows in pictures. I had the same problems.

Before create this command/method, I think we must investigate: why child objects inherit background?

One problem is autofillBackGround(.T.), but I removed it. But this setting is fired on when you use "Backcolor" and - I think - "Color". Can you do some test about this?
A simple form with a background image, one label and one button very simple (no color, no background, only position and caption). If work fine, add a backcolor.

Please remember to update your HMG4 with SVN.

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 »

Luigi,

I think my code above will work with causing problems. Here it works well.
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.
I'm sorry I don't understand what code work fine. The second one (your example) is like Rossine.
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?
We can choose many ways, but we are developping a "general" library and not a "personal" library. I wrote this, because some time it's easy to take a way but can be dangerous. Today, you can use StyleSheet() method to handle this. Is there a problem with this method? We must solve it.

Second: you use "border-image": what means? Is a CSS3 styling to use image as border..... I know "background-image" to be used to paint a background..... :?:
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: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.
l3whmg wrote:We can choose many ways, but we are developping a "general" library and not a "personal" library. I wrote this, because some time it's easy to take a way but can be dangerous. Today, you can use StyleSheet() method to handle this. Is there a problem with this method? We must solve it.
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.
l3whmg wrote:Second: you use "border-image": what means? Is a CSS3 styling to use image as border..... I know "background-image" to be used to paint a background..... :?:
He he, I just used Rossine´s code without thinking ... you´re right.

More infos about Qt-style here: http://doc.qt.nokia.com/qq/qq20-qss.html
Post Reply