[Sloved] Help with getting a image to fit onto a button
Posted
#1
(In Topic #1180)
Enthusiast

I am using the following code to load a image from the database onto a key
Does anyone know how I can make the image fit onto the button and leave a space at the bottom for the text of the button?
I have a Windows application that loads the image and on that it fits fine but when I load the data in on the Gambas app the image is not fitting on the key
Any pointers is welcome
Posted
Guru

/comp/gb.qt4/picture/stretch - Gambas Documentation
and with gambas button images are placed to the left of the text not above or below
you'll have to make a custom button/function to do that
Posted
Guru

BruceSteers said
and with gambas button images are placed to the left of the text not above or below
you'll have to make a custom button/function to do that
Here is a function that does that trick.
It makes a picture that consists of the icon and Paints the text below the icon. then sets the button picture as the picture with text.
Note: do not set Button1.Text as it is now in the image
EDIT: fixed
Code (gambas)
- ' make Button1.Picture a picture with text below it.
- '' Make a picture with text below it. can be used on any object that has a .Text and a .Picture property.
- Obj.Text = "" ' make sure Obj has not got text
- ' use Paint.class to draw the icon and text to the picture
- Paint.Begin(p)
- Paint.DrawPicture(hIcon, (Obj.W - hIcon.W) / 2, 4, hIcon.Width, hIcon.Height)
- Paint.End
Posted
Guru

Here is a function that does that trick.
It does, BUT only with gb.gui. If I use gb.gui.qt all I get is a very black button!
Posted
Guru

cogier said
Here is a function that does that trick.
It does, BUT only with gb.gui. If I use gb.gui.qt all I get is a very black button!
That must be a bug in gb.qt5 then. the code is sound.
Posted
Guru

here's how it looks on my system…
Posted
Guru

Posted
Guru

So I guess qt just does not initialize a picture cleanly unless explicitly told to be transparent.
And if not transparent then a bg color needs painting first.
Posted
Guru

Benoit said
Like Image, Picture contents is uninitialized by default - but if it's not specified in the wiki.
GTK+ component is a bit different, because Image and Picture are actually the same object internally.
So, your new Image or Picture may be initialized by default, but you can't rely on that, and suppose that
the initial contents is random.
I have updated the wiki Picture._new page to state this.
/comp/gb.qt4/picture/_new - Gambas Documentation
So i guess my "workarounds" are not so much workarounds and more like "how you should properly do it" :-/
lol
Posted
Enthusiast

Thank you BruceSteers you have gotten me out of some tight issues in the past with this project.
Posted
Enthusiast

BruceSteers said
Code (gambas)
' make Button1.Picture a picture with text below it. '' Make a picture with text below it. can be used on any object that has a .Text and a .Picture property. Obj.Text = "" ' make sure Obj has not got text ' use Paint.class to draw the icon and text to the picture Paint.Begin(p) Paint.DrawPicture(hIcon, (Obj.W - hIcon.W) / 2, 4, hIcon.Width, hIcon.Height) Paint.End
Hi
Quick question about your excellent code that works a treat what do I change to make the text a size smaller?
Posted
Guru

AndyGable said
BruceSteers said
Code (gambas)
' make Button1.Picture a picture with text below it. '' Make a picture with text below it. can be used on any object that has a .Text and a .Picture property. Obj.Text = "" ' make sure Obj has not got text ' use Paint.class to draw the icon and text to the picture Paint.Begin(p) Paint.DrawPicture(hIcon, (Obj.W - hIcon.W) / 2, 4, hIcon.Width, hIcon.Height) Paint.End
HiBruceSteers
Quick question about your excellent code that works a treat what do I change to make the text a size smaller?
You're welcome
Use Paint.Font to change the text attributes
Posted
Enthusiast

BruceSteers said
So simple I though it was going to be something super complicated
1 guest and 0 members have just viewed this.




