Image overlap with alphachannel doesn't work on QT - c++

I've put two label of the same dimension overlapped on my GUI. On the first, that is on the back there is one image set by the pixmap of the label. The second label has another image set by pixmap that is trasparent in some pixel. During design i can see the back image via the front image. When I execute the program, the trasparent pixel of the second image are transformed into white pixel, so i cant see the back image. I'm using QT 5.10. The image are in .png format.

I've resolved putting autoFillBackground on and i've changed the color of window in palette putting a transparent color

Related

Paint application Qt

I am trying to create a simple paint application using Qt Creator. I want to have a rectangular area on QDialog in which I can draw an image using mouse. The image format will be QImage::Format_Mono (Black and white, pixel indexes are either 0 or 1). I will use pixel indexes for simple image processing purpose, which operates on simple 1 and 0 pixel values, so Format_Mono is essential.
Now the application does its job, but the image (painting area) is stuck at left top part (positioned at x=0 and y=0). I want to have rectangular image editor part at any x and y coordinates I want.
To create the image editor I defined a QImage in dialog.h
QImage image;
In constructor of the Dialog I have:
image = QImage(ui->label->size(), QImage::Format_Mono);
image.fill(Qt::black);
As you can see in above code, I have a QLabel named label in my user interface. I want to put the image editor part in that label (or do something similar).
I checked the QImage documentation, but could not find a function to change the position of the image. Or, it would also be good if I could find any other way to put the image (image editor) in QLabel.
What can I do to have that feature in my application?
EDIT: The created image editor part has the same size as the label (as it should be the case), but image editor (QImage) starts at x=0 and y=0 only.

Set transparency of an image on openFrameworks

I'm working on openFrameworks and I want to set the transparency of an image in order to modify it when I press a button, but I don't know how to implement this parameter.
In which way can I change this value? Is there a particular function to manage the transparency of an image?
check out http://openframeworks.cc/ofBook/chapters/intro_to_graphics.html
ofEnableAlphaBlending();
ofSetColor(255,0,0,127); # this would be a 50% transparent red color
ofDrawRectangle(20,20,100,100);
ofDisableAlphaBlending();

Qt rendering to offscreen display, copy to visible without overwritng the background

I am using Qt5.6, I have developed several widgets that render the content to an off-screen bitmap then copy the final image to the visible area.
I have an area on the visible display that shows a video feed, I want to copy the images over the video without overwriting the background and avoiding flicker.
I am currently creating the off-screen image using a 'QPixmap', I then create a painter using the Pixmap and draw as to the off-screen image. When the image is ready I then call the 'toImage' function to return a 'QImage' and then copy this to the visible display.
A lot of the widget contains lines and circles, a lot of which are not filled.
I've seen other posts not using a QPixmap, just using a 'QImage', should I be using a 'QPixmap' at all?
Question is how to copy the image from the off-screen area to the visible area without overwriting the background?
The key to transparency is that the overlay image has got an alpha channel. QPixmap uses the graphics format of the underlying graphics system which should include an alpha channel. For QImage, the format can be explicitly specified and it should be QImage::Format_ARGB32_Premultiplied, see [1]: http://doc.qt.io/qt-5/qimage.html#Format-enum
To get a a fully transparent QImage/QPixmap in the first place, call QPixmap/QImage::fill(QColor(0, 0, 0, 0)); before creating the QPainter.
The 4th parameter is the alpha channel which is 255 (full opacity) by default).
Unfortunately I can't give advice whether QPixmap or QImage is faster for your setup.
Provided the compositing operation with the videofeed considers the alpha-channel, this should solve your problem.

Qt - Grabbing pixmap from a Widget doesn't take proper alpha channel

I'm currently using the QWidget::grab() function to acquire a QFrame's pixmap (and all of its children), but the function doesn't seem to take into account if the widget doesn't have any background.
You see, my QFrame is set to "setAutoFillBackground(false)", but when its pixmap is grabbed, it seems to paint the default light-pinkish background instead of full transparency.
Replacing the pixmap with a picture containing an alpha channel works fine.
The situation I'm using this in is with QGL, so the pixmap is getting rendered later on as a texture.
I changed the frame's palette's background to contain 0 alpha. This fixed the program.
Although I still believe that the grab function should take into account the bool that was set for filling the background or not - since not autofilling the background equates to the same net visual effect normally, just not when grabbed.

MFC dialog and form

I have a dialog (there are 3 edit controls in order to display 3 color channels RGB), I use openCV to open an image in a new form. What I want is when I move the mouse to any point on the image, each of the RGB color values will be shown in 3 edit boxed (on the dialog). How can I do that?
Thanks!!!
Perhaps this will help:
OpenCV rgb value for cv::Point in cv::Mat
To get the current cursor position you can use GetCursorPos and eventually ScreenToClient functions.