PDA

View Full Version : problem of opacity for textLabel



Stephano
9th May 2006, 10:27
Hello!

I ve an text Label with palette backgrounColor(default set the palette of parent)

I would like have a Label with not Color Font(tital opacity)




thanks

zlatko
9th May 2006, 10:56
Hm..can you give us extended explain?
Are you mean set foreground color for label?
As i know you can set opacity only for widget not for fonts :)
Also tell what version of Qt you use :)

Stephano
9th May 2006, 12:47
hello

yes ,sure ,i mean foregroundColor of widget.
but the pb is palettebackgrouncolor:
So,opacity is for "font "not for widget(String)
then I would like have a widget label with total opacity of Font (or backgrpoundcolor).

Thanks

jpn
9th May 2006, 14:28
Huh... I might be misunderstanding the half of what you are trying to say, but...



QColor color(Qt::yellow);
color.setAlpha(150); // set alpha level for text color (0-255)
QPalette pal = label->palette();
if (label->textFormat() == Qt::RichText)
pal.setColor(QPalette::Text, color); // if using rich text
else
pal.setColor(label.foregroundRole(), color); // otherwise if not using rich text
label->setPalette(pal);

Stephano
10th May 2006, 09:49
Hello!

Thanks very match for your response.
Qt3 has not the method setAlpha:this is a problem!
So,
my code is:
void SAG_Text::SAG_text_afficher()
{
QRgb rgb,rgb1;
this->setGeometry(*text_rectangle);

rgb1=text_state.Text_IDLE.Font_Color;
QColor color1=QColor(rgb1,0xffffffff);
this->setPaletteForegroundColor(color1);
//this->setPaletteForegroundColor(*text_color_contents);

this->setFont(*text_font);
this->setText(*text_contents);
if(opacity==TRUE)
{
rgb=text_state.Text_IDLE.Background_Color;
QColor color=QColor(rgb,0xffffffff);
this->setPaletteBackgroundColor(color);

}
else
{
QPainter *p=new QPainter();
p->setBackgroundMode( Qt::TransparentMode );
this->drawFrame(p); }
this->show();
}

But ,no result!

Stephano
12th May 2006, 08:57
i would like have a text transparent:(Transparence of cadre of text,not of contents)the user of my application can choose between 2 choice:

transparent
opaque


So , qt 4 can resolve the pb with Qcolor.setAlpha(..);
But ,i have many pb of installation of Qt4.

then ,how can i ,for exemple ,use Qpainter (paintEvent...) to define a transparence.
If there are other solutions or explications, help me ,please!
My regards!

Stephano
12th May 2006, 11:36
i would like have a text transparent :
Transparence of cadre of text,not of contents)
the user of my application can choose between 2 choice:
transparent
opaque

So , qt 4 can resolve the pb with Qcolor.setAlpha(..);
But ,i have many pb of installation of Qt4.

then ,how can i ,for exemple ,use Qpainter (paintEvent...) to define a transparence.
If there are other solutions or explications, help me ,please!
My regards!

wysota
12th May 2006, 12:33
Please, do not start multiple threads on the same subject! This is fourth or fifth thread you start about the same thing. Please use a single thread which is opened for discussion!

Stephano
16th May 2006, 14:21
hello!

i wouls like draw a Qlabel.
i need choose between :
tansparence or no!

the pb is qthas not setAlpha!
so, how can i use Qpainter for exemple ,to have a backgroundColor of text transparent
.It s urgency!

Thanks!!!!

jacek
16th May 2006, 14:31
Please, don't start multiple threads on the same problem or else...

Stephano
16th May 2006, 14:34
Sorry Mr.jacek ,
but it s very urgent!
Can u help me?

wysota
16th May 2006, 14:42
What about jpn's answer?

jacek
16th May 2006, 14:50
but it s very urgent!
There are no urgent matters --- this is a community forum. People answer questions in their free time.


Can u help me?
What exactly do you want to achieve? What is under the label?

One of the QQ articles (http://doc.trolltech.com/qq/qq16-background.html) suggests three solutions:

We need a different approach if we want the parent widget's background to shine through. [...] In Qt 3, there are several ways to simulate this feature:
You can use QPainter::redirect() and then call the parent widget's paintEvent() to have the parent draw itself onto the widget's background directly.
You can set a transparency mask (QWidget::setMask()). The parent widget is aware of the child widget's mask and will paint all areas not covered by the mask.
If the parent doesn't paint anything underneath the child widget other than its background, you can fill the child widget's background by inheriting the parent widget's brush and applying a suitable offset by calling QWidget::setBackgroundOrigin().

Stephano
16th May 2006, 16:11
thanks!very match

Stephano
17th May 2006, 09:21
i would like a tewt Label
witch contents only the string
So the cadre of label must be transparent
Because the text will be draw in the bitmap(no backgroun color)
thanks

jacek
17th May 2006, 14:02
Because the text will be draw in the bitmap(no backgroun color)
Is that bitmap the background of your window or is it displayed by some widget (for example a QLabel)?

You might try to reimplement the paintEvent() for your widget and draw that text there.

Stephano
18th May 2006, 07:57
i would like draw only the String of Qlabel
So ,how i implemente
paintEvent()
please?
can u give me an exemple!

wysota
18th May 2006, 10:36
Have you tried simply using QWidget::backgroundOrigin property? If you assign both your label and its parent the same bitmap as a background, it should be possible to blend them together.

Stephano
18th May 2006, 15:30
thanks
but,
to set the color of parent dont resolve the problem.
i neded a realy transparent label in my application

wysota
18th May 2006, 16:15
What for? Maybe you could explain what do you intend to do with it.

Stephano
19th May 2006, 10:46
What for? Maybe you could explain what do you intend to do with it.

i explique:
:confused:
i need the color transparense
because:
-when the user move some widgets(herits from Qframe or qlabel) by the cursor;
the upper widget must be transparent ansd dont has the color of his parent,
just the color of background will be transparent....
i hope that u will understand the problem

My regards!:rolleyes:

jacek
19th May 2006, 10:52
-when the user move some widgets(herits from Qframe or qlabel) by the cursor;
the upper widget must be transparent ansd dont has the color of his parent,
just the color of background will be transparent....
Then maybe you need QCanvas? If not, then try the first method from the article I mentioned earlier (i.e. "You can use QPainter::redirect() and then call the parent widget's paintEvent() to have the parent draw itself onto the widget's background directly.").