Drawing html with transparent background - html

I'm currently trying to draw an HTML formatted text of a QTextEdit into a QPixmap with a transparent background, to use it as an overlay for another widget.
My first attempt was, to use the QTextDocument of the QTextEdit and use drawContents() to draw it to a QPixmap.
As a second attempt, I passed the HTML to a QStaticText and painted this to my QPixmap, using a QPainter.
Both approaches paint the final text as expected, however, the background of the QPixmap is always grey. Also setting the background-color of the QTextEdit, inside the StyleSheet, to transparent does no change.
Is there any way, that I can make the background transparent?

Apparently, after some more research, I found the solution.
My QPixmap was not transparent at all, even before rendering the text. I came across this blog post, in which the composition mode of the QPainter is set to CompositionMode_Source using a call to setCompositionMode().

Related

"destination-out"-like blending behavior using CSS?

I have an image. I have a second graphical element ontop of this image, whose alpha I want to use to "hide" parts of the image below it, while the top element itself isn't shown.
Something along the lines of
CanvasRenderingContext2D.globalCompositeOperation = "destination-out"
This top element will change transparency and shape live, so prerendering everything onto a seperate canvas won't be an option.
I was thinking of "multiply" but it didn't do what I expected it to. I thought if I put the alpha of the top layer to "0", that would be multiplied with the layer below, also making it transparent. (I was sad it didn't work)
Is there someway to "hack" this using the existing CSS blending modes (or any other method)?
As an alternative, consider mask-image (however, note that currently there's no support for this on IE / Edge):
img {
-webkit-mask-image: url(http://www.lordtennyson.ca/uploads/1/2/4/2/12421219/paw_print_small.png);
mask-image: url(http://www.lordtennyson.ca/uploads/1/2/4/2/12421219/paw_print_small.png);
}
<img src="http://www.dizzydi.com/uploads/6/5/6/5/65656887/6168555.jpg" />

onmouseover just on the non-transparent part of the image

I'm stuck with the menu below. All the website needs to be in HTML.
http://hpics.li/740c57f
WHAT: I want to have an hover image for all the different parts when the mouse go on it. (event/brand/website/print/UI/VIDEO)
PROBLEM: The images are overlapping and the mouseover start when i'm on the transparency of the png.
SOLUTIONS I TRIED: Imagemap to detect the zone and then put javascript code inside the AREA. doesn't work.
Imagemap to detect the zone, put an id in the AREA and use a separated JQUERY with .hover(function(). doesn't work.
Use z-index: impossible because there will be always an image that will hide the one under.
QUESTION: If I can't use ImapeMAP to select my zone and use CSS or JQUERY, how can I do ?
Thank you so much for your help!
Might be too late but the exact case can actually be solved by a class I wrote around 3 months ago. It allows you to check whether you're on a transparent area or not and also check for other elements behind the transparent area, this allows to overlap multiple transparent images and correctly jump from one image to another at the correct point.
http://www.cw-internetdienste.de/pixelselection/

Background-image opacity and :hover

Is it possible to only trigger a div's mouseover when the cursor is over an opaque part of the div's background image? Perhaps via Javascript?
All I can find with Google are old IE PNG fixes.
This looks like a similar question to this one: Hit detection on non-transparent pixel
I suppose this could also be done for background image by getting the attribute with jQuery:
$('#myDiv').css('background-image');
I haven't personally done this, but it seems like a viable solution. This will only work for modern browsers, but you should be able to make it back-compatible with excanvas.
It is possible, just not very easily. You'll have to use a lot of Javascript.
You'd want to attach to your <div>'s onmousemove event, which returns the X,Y coordinates of the cursor. Your event handler function would then test to see if the cursor is in the correct place in order to trigger an alternative onmouseover event.
Implementing the "is the cursor over an opaque pixel or not?" test can be done two ways: the first is to create a simple mathematical expression (say if the opaque parts of the image make neat rectangles, circles or polygons). The more difficult (and less browser-supported) way is to load the background image into a Canvas object and then get the current pixel value's opacity figure and take it from there, like so:
var pixel = canvas.getImageData(x, y, 1, 1).data;
var alpha = pixel[3]; // assuming RGBA
if( alpha > threshold ) onMouseOver(); // raise the event
Another alternative is to create an entirely transparent div (or some other element) positioned and sized so that it only covers the opaque part of the div below, then just test the mouseover of that element's box.
It's a bit of tweaking but why don't you add a class to your opaque div, and use JavaScript to check for it?
In jQuery:
$('div').mouseover(function(){
if ($(this).is('.opaque')) {
//Some actions
}
});

How to show a two color area?

Since now, in the design of one of the websites I work, I've been using a graphic to decorate the header section that consists in a diagonal division white in the lower side and transparent in the upper side. The result is this:
If I change upper color, as the image is transparent in its upper area the effect seems perfect:
Now, I need to allow users to change page background and that's the problem:
Background changes to red, but the image I used to decorate the header doesn't change.
Is there any way to allow users to change the background without ruin the header decoration?
Note that store a copies of the decoration imagen in different colors is not an option due I allow users to choose any 24-bit color. Also, to change the image in real time like explained here isn't an option due multiple users may access the same file.
You could try changing the image in realtime using data URIs: https://developer.mozilla.org/en/data_URIs
With a data URI, you can do something like the following: <img src="data:image/png;base64,SGVsbG8sIFdvcmxkIQ%3D%3D" />. The image can be changed dynamically in JS by generating a new image and setting the src attribute to the new data URI.
You will need to find a suitable format for generating images in JS though. I have used pnglib.js before, and it works, but it might be slower than you'd prefer. You might need to test some different libraries and image formats to see which can be generated quickly. Also, make the image as small as possible - should be only the area with the diagonal split, the area to the right can be done with a div instead.
Alternatively, you could generate a unique image server-side via a script. Make a script that takes a GET parameter for the background color and generates the appropriate image (for PHP, you can use GD or IMagick). Advantage is that the server may generate the image and send it to the client quicker than the client could generate it in JS.
Add the following to the div with the background image:
position: absolute;
top: 0px;
right: 0px;
The problem currently is that the background cannot overlap your div with the background image. Adding the position: absolute gives your div some kind of "ghost box" model, thus allowing the background of the body to overlap it.
P.S.: you can also play with z-index if you want to.

how to set one continuous background image for multiple elements

I've been wrecking my brain trying to figure this out. is there any way to set one background image in css for multiple elements? I have a square-ish speech bubble, made with regular css, the triangle made with the border technique, but i want an background image to fill them both so it looks like a cut out all together.
I dont know any other way to design a solid shape using html/css other than squares and rectangles. If i could create a speech bubble as one solid shape, then giving it a bg would be simple lol.
I was wondering about html5's drawing capabilites, but im not sure...
Any ideas?
Edit: No, there's no option to do what you want. But if you wanna do spech bubbles, you can check any of these links:
http://nicolasgallagher.com/pure-css-speech-bubbles/demo/
http://konigi.com/tools/css-tooltips-and-speech-bubbles
http://desandro.com/resources/css-speech-bubble-icon/