Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, December 2006
painting image or pixmap prob


Message 1 in thread

Hello,

in respect to my lack of experience with QT-GUI-programming, I'm
desperately searching a solution of my problem or a hint to it. First of
all, sorry to all of you who regard this as spam, but I'm thinking about
this some days and didn't get the right solution. My Frustration grew up
a lot and finally, I'm posting here... :-/

Here is, what I want to do:
We have got a custom style (uh, we really exhausted all possibilities in
QT3...) and I shall port it from QT3 to QT4. In this style, I now want
to paint a new dialog frame as a QImage or QPixmap. I read some .pngs
containing the frame, calculate the resulting Image/Pixmap and then
appears my problem: the corners. They are rounded within the pngs and I
defined the overlaying parts as transparent in these files. By default,
QT loads the pngs and set the alpha channel to opaque. Now I'm playing
with all the qpainter, qimage and qpixmap functions, but with no real
success. All masks didn't work and setting the alpha channel is
pedestrian, because I guess I need another image to set the alpha
channel of my image and that alpha image will be rectangular again. *argh*
So, did you know a simple way to acchieve this?
I guess, it is just one of these moments, where I am blind as a bat...

Thx for help, Clemens

--
 [ signature omitted ] 

Message 2 in thread

You should create a QRegion, definining the region to paint, you may
need to create the region by hand, or via createHeuristicMask.

However, the createHeuristicMask is limited, to searching for 1 color,
and mapping that color to the mask.

Here is a function, I created, a that takes a QImage, and can create a
mask from it, based on the alpha channel.  

Once you have the region as a mask, you set the mask on the dialog
(using setMask) and only the region that is contained in the mask will
be painted.

Note, if you are primarily concerned about your 4 corners, create 4 sub
masks, of the image to be NOT to be painted for each corner.

Then create 1 mask for the whole region, and subtrack off the previous 4
regions.  QRegion supplies operator -= to make this quite easy.

	// returns a region for the image, whereever the alpha setting
is 0, meaning totally opaque

The following function will  return a QRegion based on the alpha channel
of the image.

Scott


	QRegion createMaskRegion( const QImage & image, bool posMask )
	{
		if ( image.isNull() )
			return QRegion();

		if (image.depth() != 32) {
			QImage img32 =
image.convertToFormat(QImage::Format_RGB32);
			return createMaskRegion( img32, posMask );
		}

		int width = image.width();
		int height = image.height();
		QRegion retVal;

		for( int yy = 0; yy < height; ++yy )
		{
			// guarented to be 32 bit by the check above
			QRgb *currLine = (QRgb *)image.scanLine( yy );
			int xstart = -1;
			int xcurr = -1;
			QRgb * currVal = currLine;
			for( int xx = 0; xx < width; ++xx, ++currVal )
			{
				int alpha = qAlpha( *currVal );
				if ( ( posMask && alpha != 0 ) || (
!posMask && alpha == 0 ) )
				{
					if ( xstart == -1 )
						xstart = xx;
					xcurr = xx;
				}
				else if ( xcurr != -1 )
				{
					retVal += QRegion( xstart, yy,
xcurr - xstart + 1, 1 );
					xstart = xcurr;
					xcurr = -1;
				}
			}
			if ( xcurr != -1 )
			{
				retVal += QRegion( xstart, yy, xcurr -
xstart + 1, 1 );
			}
		}

		return retVal;
	}

> -----Original Message-----
> From: Clemens Clausen [mailto:clausecs@xxxxxxxxxxxxxxxxxx]
> Sent: Monday, December 11, 2006 12:37 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: painting image or pixmap prob
> 
> Hello,
> 
> in respect to my lack of experience with QT-GUI-programming, I'm
> desperately searching a solution of my problem or a hint to it. First
of
> all, sorry to all of you who regard this as spam, but I'm thinking
about
> this some days and didn't get the right solution. My Frustration grew
up
> a lot and finally, I'm posting here... :-/
> 
> Here is, what I want to do:
> We have got a custom style (uh, we really exhausted all possibilities
in
> QT3...) and I shall port it from QT3 to QT4. In this style, I now want
> to paint a new dialog frame as a QImage or QPixmap. I read some .pngs
> containing the frame, calculate the resulting Image/Pixmap and then
> appears my problem: the corners. They are rounded within the pngs and
I
> defined the overlaying parts as transparent in these files. By
default,
> QT loads the pngs and set the alpha channel to opaque. Now I'm playing
> with all the qpainter, qimage and qpixmap functions, but with no real
> success. All masks didn't work and setting the alpha channel is
> pedestrian, because I guess I need another image to set the alpha
> channel of my image and that alpha image will be rectangular again.
*argh*
> So, did you know a simple way to acchieve this?
> I guess, it is just one of these moments, where I am blind as a bat...
> 
> Thx for help, Clemens
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 3 in thread

If you're using Qt4, you shouldn't have to do anything to enable
transparency.

It should work correctly since the backend is fully 32bit RGBA.

Ben

> -----Original Message-----
> From: Clemens Clausen [mailto:clausecs@xxxxxxxxxxxxxxxxxx] 
> Sent: Monday, December 11, 2006 10:37 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: painting image or pixmap prob
> 
> Hello,
> 
> in respect to my lack of experience with QT-GUI-programming, 
> I'm desperately searching a solution of my problem or a hint 
> to it. First of all, sorry to all of you who regard this as 
> spam, but I'm thinking about this some days and didn't get 
> the right solution. My Frustration grew up a lot and finally, 
> I'm posting here... :-/
> 
> Here is, what I want to do:
> We have got a custom style (uh, we really exhausted all 
> possibilities in
> QT3...) and I shall port it from QT3 to QT4. In this style, I 
> now want to paint a new dialog frame as a QImage or QPixmap. 
> I read some .pngs containing the frame, calculate the 
> resulting Image/Pixmap and then appears my problem: the 
> corners. They are rounded within the pngs and I defined the 
> overlaying parts as transparent in these files. By default, 
> QT loads the pngs and set the alpha channel to opaque. Now 
> I'm playing with all the qpainter, qimage and qpixmap 
> functions, but with no real success. All masks didn't work 
> and setting the alpha channel is pedestrian, because I guess 
> I need another image to set the alpha channel of my image and 
> that alpha image will be rectangular again. *argh* So, did 
> you know a simple way to acchieve this?
> I guess, it is just one of these moments, where I am blind as a bat...
> 
> Thx for help, Clemens
> 
> --
> To unsubscribe - send a mail to 
> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the 
> subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 

--
 [ signature omitted ] 

Message 4 in thread

I thaught that, too...
I load my eight .pngs and paint them into an qImage of type ARGB32. This
image got an initial fill with 0x00FFFFFF. So far, the alpha channel is
maintained correctly. Therefore, I expect a dialog with total
transparent corners. But on the screen, it still has these annoying
white corners. So, the fault has to be in the painting step. Now, I have
to take a look why this is done... But on the spur of the moment, I am
missing an idea. I'm just calling QPainter::drawImage(). Took a look
after the composition mode and this is right (source over) . Or am I
wrong and I have to set a mask in either case?

Thx for your help (to narrow the problem down) and, of course, thx to
Scott for his help!

Clemens

Benjamin Ari Schleimer wrote:
> If you're using Qt4, you shouldn't have to do anything to enable
> transparency.
>
> It should work correctly since the backend is fully 32bit RGBA.
>
> Ben
>
>   
>> -----Original Message-----
>> From: Clemens Clausen [mailto:clausecs@xxxxxxxxxxxxxxxxxx] 
>> Sent: Monday, December 11, 2006 10:37 AM
>> To: qt-interest@xxxxxxxxxxxxx
>> Subject: painting image or pixmap prob
>>
>> Hello,
>>
>> in respect to my lack of experience with QT-GUI-programming, 
>> I'm desperately searching a solution of my problem or a hint 
>> to it. First of all, sorry to all of you who regard this as 
>> spam, but I'm thinking about this some days and didn't get 
>> the right solution. My Frustration grew up a lot and finally, 
>> I'm posting here... :-/
>>
>> Here is, what I want to do:
>> We have got a custom style (uh, we really exhausted all 
>> possibilities in
>> QT3...) and I shall port it from QT3 to QT4. In this style, I 
>> now want to paint a new dialog frame as a QImage or QPixmap. 
>> I read some .pngs containing the frame, calculate the 
>> resulting Image/Pixmap and then appears my problem: the 
>> corners. They are rounded within the pngs and I defined the 
>> overlaying parts as transparent in these files. By default, 
>> QT loads the pngs and set the alpha channel to opaque. Now 
>> I'm playing with all the qpainter, qimage and qpixmap 
>> functions, but with no real success. All masks didn't work 
>> and setting the alpha channel is pedestrian, because I guess 
>> I need another image to set the alpha channel of my image and 
>> that alpha image will be rectangular again. *argh* So, did 
>> you know a simple way to acchieve this?
>> I guess, it is just one of these moments, where I am blind as a bat...
>>
>> Thx for help, Clemens
>>
>> --
>> To unsubscribe - send a mail to 
>> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the 
>> subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
>>     


-- 
 [ signature omitted ] 

Message 5 in thread

Hi Clemens,

I thought yes, you have to set a mask because you are painting a message 
box which is a top level window; like in the tux example (this is fairly 
similar to the method last described by Scott Aron Bloom in the thread).

Clemens Clausen escribió:
> I thaught that, too...
> I load my eight .pngs and paint them into an qImage of type ARGB32. This
> image got an initial fill with 0x00FFFFFF. So far, the alpha channel is
> maintained correctly. Therefore, I expect a dialog with total
> transparent corners. But on the screen, it still has these annoying
> white corners. So, the fault has to be in the painting step. Now, I have
> to take a look why this is done... But on the spur of the moment, I am
> missing an idea. I'm just calling QPainter::drawImage(). Took a look
> after the composition mode and this is right (source over) . Or am I
> wrong and I have to set a mask in either case?
>
> Thx for your help (to narrow the problem down) and, of course, thx to
> Scott for his help!
>
> Clemens
>
> Benjamin Ari Schleimer wrote:
>   
>> If you're using Qt4, you shouldn't have to do anything to enable
>> transparency.
>>
>> It should work correctly since the backend is fully 32bit RGBA.
>>
>> Ben
>>
>>   
>>     
>>> -----Original Message-----
>>> From: Clemens Clausen [mailto:clausecs@xxxxxxxxxxxxxxxxxx] 
>>> Sent: Monday, December 11, 2006 10:37 AM
>>> To: qt-interest@xxxxxxxxxxxxx
>>> Subject: painting image or pixmap prob
>>>
>>> Hello,
>>>
>>> in respect to my lack of experience with QT-GUI-programming, 
>>> I'm desperately searching a solution of my problem or a hint 
>>> to it. First of all, sorry to all of you who regard this as 
>>> spam, but I'm thinking about this some days and didn't get 
>>> the right solution. My Frustration grew up a lot and finally, 
>>> I'm posting here... :-/
>>>
>>> Here is, what I want to do:
>>> We have got a custom style (uh, we really exhausted all 
>>> possibilities in
>>> QT3...) and I shall port it from QT3 to QT4. In this style, I 
>>> now want to paint a new dialog frame as a QImage or QPixmap. 
>>> I read some .pngs containing the frame, calculate the 
>>> resulting Image/Pixmap and then appears my problem: the 
>>> corners. They are rounded within the pngs and I defined the 
>>> overlaying parts as transparent in these files. By default, 
>>> QT loads the pngs and set the alpha channel to opaque. Now 
>>> I'm playing with all the qpainter, qimage and qpixmap 
>>> functions, but with no real success. All masks didn't work 
>>> and setting the alpha channel is pedestrian, because I guess 
>>> I need another image to set the alpha channel of my image and 
>>> that alpha image will be rectangular again. *argh* So, did 
>>> you know a simple way to acchieve this?
>>> I guess, it is just one of these moments, where I am blind as a bat...
>>>
>>> Thx for help, Clemens
>>>
>>> --
>>> To unsubscribe - send a mail to 
>>> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the 
>>> subject or the body.
>>> List archive and information: http://lists.trolltech.com/qt-interest/
>>>
>>>
>>>     
>>>       
>
>
>   

--
 [ signature omitted ] 

Message 6 in thread

Oh, is clemens trying to draw the toplevel window? 
Sorry I missed that.
Then he needs to grab the desktop as a Qimage/Qpixmap and use that as his BG image to draw on top of. Otherwise he's blending with the default BG color (I guess white in his case)
Search the archive for ways to do it.

Cheers,
Ben

> -----Original Message-----
> From: Javier Díaz [mailto:jdiaz@xxxxxxxxxxx] 
> Sent: Monday, December 11, 2006 12:58 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: painting image or pixmap prob
> 
> Hi Clemens,
> 
> I thought yes, you have to set a mask because you are 
> painting a message box which is a top level window; like in 
> the tux example (this is fairly similar to the method last 
> described by Scott Aron Bloom in the thread).
> 
> Clemens Clausen escribió:
> > I thaught that, too...
> > I load my eight .pngs and paint them into an qImage of type ARGB32. 
> > This image got an initial fill with 0x00FFFFFF. So far, the alpha 
> > channel is maintained correctly. Therefore, I expect a dialog with 
> > total transparent corners. But on the screen, it still has these 
> > annoying white corners. So, the fault has to be in the 
> painting step. 
> > Now, I have to take a look why this is done... But on the 
> spur of the 
> > moment, I am missing an idea. I'm just calling 
> QPainter::drawImage(). 
> > Took a look after the composition mode and this is right 
> (source over) 
> > . Or am I wrong and I have to set a mask in either case?
> >
> > Thx for your help (to narrow the problem down) and, of 
> course, thx to 
> > Scott for his help!
> >
> > Clemens
> >
> > Benjamin Ari Schleimer wrote:
> >   
> >> If you're using Qt4, you shouldn't have to do anything to enable 
> >> transparency.
> >>
> >> It should work correctly since the backend is fully 32bit RGBA.
> >>
> >> Ben
> >>
> >>   
> >>     
> >>> -----Original Message-----
> >>> From: Clemens Clausen [mailto:clausecs@xxxxxxxxxxxxxxxxxx]
> >>> Sent: Monday, December 11, 2006 10:37 AM
> >>> To: qt-interest@xxxxxxxxxxxxx
> >>> Subject: painting image or pixmap prob
> >>>
> >>> Hello,
> >>>
> >>> in respect to my lack of experience with QT-GUI-programming, I'm 
> >>> desperately searching a solution of my problem or a hint to it. 
> >>> First of all, sorry to all of you who regard this as 
> spam, but I'm 
> >>> thinking about this some days and didn't get the right 
> solution. My 
> >>> Frustration grew up a lot and finally, I'm posting here... :-/
> >>>
> >>> Here is, what I want to do:
> >>> We have got a custom style (uh, we really exhausted all 
> >>> possibilities in
> >>> QT3...) and I shall port it from QT3 to QT4. In this style, I now 
> >>> want to paint a new dialog frame as a QImage or QPixmap.
> >>> I read some .pngs containing the frame, calculate the resulting 
> >>> Image/Pixmap and then appears my problem: the corners. They are 
> >>> rounded within the pngs and I defined the overlaying parts as 
> >>> transparent in these files. By default, QT loads the pngs and set 
> >>> the alpha channel to opaque. Now I'm playing with all the 
> qpainter, 
> >>> qimage and qpixmap functions, but with no real success. All masks 
> >>> didn't work and setting the alpha channel is pedestrian, 
> because I 
> >>> guess I need another image to set the alpha channel of my 
> image and 
> >>> that alpha image will be rectangular again. *argh* So, 
> did you know 
> >>> a simple way to acchieve this?
> >>> I guess, it is just one of these moments, where I am 
> blind as a bat...
> >>>
> >>> Thx for help, Clemens
> >>>
> >>> --
> >>> To unsubscribe - send a mail to
> >>> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in 
> the subject 
> >>> or the body.
> >>> List archive and information: 
> >>> http://lists.trolltech.com/qt-interest/
> >>>
> >>>
> >>>     
> >>>       
> >
> >
> >   
> 
> --
> To unsubscribe - send a mail to 
> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the 
> subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 

--
 [ signature omitted ] 

Message 7 in thread

Thx to your help, Ben & Javier, it is almost done... It was mainly a
combination of some minor errors ( characteristical for me, as I said,
sometimes I am blind as a bat ) and my nescience that I had to grab and
merge in order to see any result. Now, fraught with new energy, I am
facing the 3D shadow. :-P

So, again, thanks a lot, Clemens

Benjamin Ari Schleimer wrote:
> Oh, is clemens trying to draw the toplevel window? 
> Sorry I missed that.
> Then he needs to grab the desktop as a Qimage/Qpixmap and use that as his BG image to draw on top of. Otherwise he's blending with the default BG color (I guess white in his case)
> Search the archive for ways to do it.
>
> Cheers,
> Ben
>
>   
>> -----Original Message-----
>> From: Javier Díaz [mailto:jdiaz@xxxxxxxxxxx] 
>> Sent: Monday, December 11, 2006 12:58 PM
>> To: qt-interest@xxxxxxxxxxxxx
>> Subject: Re: painting image or pixmap prob
>>
>> Hi Clemens,
>>
>> I thought yes, you have to set a mask because you are 
>> painting a message box which is a top level window; like in 
>> the tux example (this is fairly similar to the method last 
>> described by Scott Aron Bloom in the thread).
>>
>> Clemens Clausen escribió:
>>     
>>> I thaught that, too...
>>> I load my eight .pngs and paint them into an qImage of type ARGB32. 
>>> This image got an initial fill with 0x00FFFFFF. So far, the alpha 
>>> channel is maintained correctly. Therefore, I expect a dialog with 
>>> total transparent corners. But on the screen, it still has these 
>>> annoying white corners. So, the fault has to be in the 
>>>       
>> painting step. 
>>     
>>> Now, I have to take a look why this is done... But on the 
>>>       
>> spur of the 
>>     
>>> moment, I am missing an idea. I'm just calling 
>>>       
>> QPainter::drawImage(). 
>>     
>>> Took a look after the composition mode and this is right 
>>>       
>> (source over) 
>>     
>>> . Or am I wrong and I have to set a mask in either case?
>>>
>>> Thx for your help (to narrow the problem down) and, of 
>>>       
>> course, thx to 
>>     
>>> Scott for his help!
>>>
>>> Clemens
>>>
>>> Benjamin Ari Schleimer wrote:
>>>   
>>>       
>>>> If you're using Qt4, you shouldn't have to do anything to enable 
>>>> transparency.
>>>>
>>>> It should work correctly since the backend is fully 32bit RGBA.
>>>>
>>>> Ben
>>>>
>>>>   
>>>>     
>>>>         
>>>>> -----Original Message-----
>>>>> From: Clemens Clausen [mailto:clausecs@xxxxxxxxxxxxxxxxxx]
>>>>> Sent: Monday, December 11, 2006 10:37 AM
>>>>> To: qt-interest@xxxxxxxxxxxxx
>>>>> Subject: painting image or pixmap prob
>>>>>
>>>>> Hello,
>>>>>
>>>>> in respect to my lack of experience with QT-GUI-programming, I'm 
>>>>> desperately searching a solution of my problem or a hint to it. 
>>>>> First of all, sorry to all of you who regard this as 
>>>>>           
>> spam, but I'm 
>>     
>>>>> thinking about this some days and didn't get the right 
>>>>>           
>> solution. My 
>>     
>>>>> Frustration grew up a lot and finally, I'm posting here... :-/
>>>>>
>>>>> Here is, what I want to do:
>>>>> We have got a custom style (uh, we really exhausted all 
>>>>> possibilities in
>>>>> QT3...) and I shall port it from QT3 to QT4. In this style, I now 
>>>>> want to paint a new dialog frame as a QImage or QPixmap.
>>>>> I read some .pngs containing the frame, calculate the resulting 
>>>>> Image/Pixmap and then appears my problem: the corners. They are 
>>>>> rounded within the pngs and I defined the overlaying parts as 
>>>>> transparent in these files. By default, QT loads the pngs and set 
>>>>> the alpha channel to opaque. Now I'm playing with all the 
>>>>>           
>> qpainter, 
>>     
>>>>> qimage and qpixmap functions, but with no real success. All masks 
>>>>> didn't work and setting the alpha channel is pedestrian, 
>>>>>           
>> because I 
>>     
>>>>> guess I need another image to set the alpha channel of my 
>>>>>           
>> image and 
>>     
>>>>> that alpha image will be rectangular again. *argh* So, 
>>>>>           
>> did you know 
>>     
>>>>> a simple way to acchieve this?
>>>>> I guess, it is just one of these moments, where I am 
>>>>>           
>> blind as a bat...
>>     
>>>>> Thx for help, Clemens
>>>>>
>>>>> --
>>>>> To unsubscribe - send a mail to
>>>>> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in 
>>>>>           
>> the subject 
>>     
>>>>> or the body.
>>>>> List archive and information: 
>>>>> http://lists.trolltech.com/qt-interest/
>>>>>
>>>>>
>>>>>     
>>>>>       
>>>>>           
>>>   
>>>       
>> --
>> To unsubscribe - send a mail to 
>> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the 
>> subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
>>     
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>