Re: How to remove background
Okay, I found the solution. It's weird though, I though I already tried that...
Anyway, resizing the window erases the content:
Code:
{
static int isResizing = 0;
if(isResizing == 0)
{
QSize size
= this
->size
();
size.setHeight(size.height()+1);
isResizing = 1;
this->resize(size);
size.setHeight(size.height()-1);
isResizing = 2;
this->resize(size);
isResizing = 3;
return;
}
else if(isResizing < 3)
{
return;
}
else
isResizing = 0;
//Now you can start painting
}
Somehow I'm thinking that I overkilled it a little bit with isResizing... am I so tired right now and just can't see a simpler solution to do that resizing thingy?
Re: How to remove background
I don't have the problem when resizing but when changing the focus. Even resizing seem to restore the corect color.
Re: How to remove background
to durbrak:
Code:
CTestWidget
::CTestWidget(QWidget* parent
){
setWindowFlags( Qt::FramelessWindowHint );
setFixedSize( 400, 400 );
mPixmap
= QPixmap( "C:\\ellipse.png" );
QBitmap mask
= mPixmap.
createHeuristicMask(true);
setMask( mask );
}
CTestWidget::~CTestWidget()
{
}
{
p.drawPixmap( 0, 0, mPixmap );
}
I knew I did it some time ago.
I attached a screen of how it looks.
The png is just a black ellipse on a white background.
The method is limited because it does not work when the image you want to display contains transparent shadings ( such as shadows ).
However, you can give the whole masked widget a shadow if you set the flags Qt::FramessWindowHint | Qt::Popup.
Although, never tested it on Mac.
regards
Re: How to remove background
kawazoe: No, you missed the point. My solution fixes the problem where the background wasn't erased by Qt (it was just painted over). Now with this solution, everytime the window wants to repaint itself, it will resize itself first (thus erasing the garbage painted before), and then paint the stuff.
marcel: Stuff like shadows is exactly what I'm trying to do the whole time :) You scaled your screenshot a little bit too much and I can't see if your circle is anti aliased or not. But I guess not, since this would be equal to shadows :)
Anyway, I can finally do that now. But here comes the kinda weird part:
I paint text and circles (anti aliased) in my widget and everything looks smooth. But if I paint a pixmap first and then the text and the circles, the circles are still smooth but now the text is crispy as hell :(
Weird, I can paint every type of form/shape smooth on my png pixmap window, but not text...
Re: How to remove background
No, it is not antialised.
For text: have you used QPainter::TextAntialiasing?
Re: How to remove background
Ha ok!
I see your point now. I will try this.
Re: How to remove background
Yeah sure, like I said.
Well, I think I figured it out how I can also paint text... but this is sooo weird (and I'm convinced that this can be fixed easily by TT!)
Okay, now let's assume I begin painting my background in the Pos(0, 0) across the window and then I paint my text (a very long string) on the x-coord by 50px:
As you can see the text is totally crispy, but the circle is smooth...
Now I do the same again, except that the background image is now positioned on the x-axis on 2px and the text on 1px on the x-axis (i.e. text.x() < background.x()):
Now as you can see the text is perfectly smooth, and all I did is to set the x-coord of the text to be -1 of that of the background and it still paints perfectly onto the background.
But do you see the last three dots at the end? No, they weirdly enough aren't smooth but still crispy... So I thought to myself "wtf!?" and inserted a dot in my QString somewhere at the beginning:
Can you believe it? It screwed up everything behind the dot...
Anyway, I thought of a workaround (not for the dot issue) - if you need to paint the text inside the background, you could just prepend alot of whitespaces:
Code:
" Something is here"
But this won't work. Though the text is inside the background, it is still crispy.
This works:
Code:
"g Something is here"
:D
Re: How to remove background
Well, I don't know about that.
It could be a problem related to text rendering ( small glyphs actually, like the dot ).
So, there is another possibility to draw text, without actually drawing text :), but paths.
You will have to use a QPainterPath and QPainterPath::addText. This way the glyphs will be converted to paths ( actually only contours ) and filled with whatever brush you have currently set.
Maybe the problem will go away.
Re: How to remove background
Yupp, I already thought of that but I wanted to give it a shot tomorrow... it's too late now :D