drawing inside a qt windows - c++

I'd like to draw a color "frame" within a QT window. So, I have
setFixedSize(WIDTH, HEIGHT);
and I'd like to draw, say, a red (filled) border within width and height. Could anyone help me out?

Depends on a couple of things:
Is it a border around an existing widget? If it's just a border around an existing widget don't go down the route of painting it yourself, it's much simpler to use Stylesheets than draw it.
If of course you need a custom or very specific style, then you're best off drawing it using the Painting System. I'd strongly suggest do it using stylesheets unless you do need specifics. The paint system can be a bit unwieldy for just adding a border to a widget.

Related

Qt widget blurred semitransparent background on Linux

Working with widgets, c++ and Linux
need something kind of:
this
but no borders and custom title.
Search for a few days, but nothing.
For now, there is a widget with setWindowFlags(Qt::FramelessWindowHint); and a peace of qss for semitransparent background. How can I blur it? Is is possible at all?
I do not think this can be done with Qt. Blurring can be done using https://doc.qt.io/qt-5/qgraphicsblureffect.html but it is only limited to the widgets painted by Qt. Which the underlying background is not, even if you manage to make your widgets transparent or semitransparent. Painting the background is always the business of the operating system (or window manager) and not the business of your application Qt.
You can certainly try to do some extreme hacking like grabbing the active screen before your window is displayed (see How to capture the current screen image using Qt?) then getting certain rectangle content of the image, which corresponds to the background of your window, then paint it blurred to the background of your application and then update it everytime you move or resize your window... But anyway, even if you manage this, this background will be static and not dynamic.
I recommend that you abandon the idea of blurry background and leave this function to the window manager and the operating system.

Suggestion wanted for MFC custom scrollbars

I want to make my own scrollbars for a custom drawn plot, like this image, what would be the best way to go?
Scrollbars should:
Only be visible when mouse hover over it (with fade in/out)
Be a part of the x/y axis of the plot, like in the picture
Not have any arrow buttons, just the thumb Thinner than the normal scrollbars
Would you suggest to:
Create everything from scratch, handling paging, scrollwheel etc.
Try to inherit CScrollBar and do my own drawing?
From what I've read, it's not very easy to customize scrollbars in MFC, for example here)
First off, these have to be scrollbar (or other) controls, not window scrollbars (used for scrolling a window).
Second, the statement "it's not very easy to customize scrollbars in MFC", is only partially true. MFC is a "thin wrapper" of Windows API, so you should better refer to the documentation of the Windows scrollbar control.
Then there is the CScrollBar class, but took a short look, and indeed, it does not really offer anything more than the Windows scrollbar does. As for the sample in the link you posted is a new (custom) control (painting everything on its own), i.e. literally "from scratch", not inheriting anything from CScrollBar.
So, you have to look into the Windows scrollbar control, and what it offers. Did take a look, and saw few things. Unfortunately there seems to be no owner-draw functionality. You can process the WM_CTLCOLORSCROLLBAR message, but this only allows you to change colors.
And according to the documentation the background color only. This appears to be the only possible customization, apart from the SBM_ENABLE_ARROWS message, which can hide the arrows. And no fading effect. If these are enough to you, you could try the Windows/MFC scrollbar, otherwise try writing your own.

How can I draw around a rectangle?

I'm using openGL to draw some animation.
I want to draw the animation in an area around a rectangle.
That rectangle are should be transparent, to show whatever windows happen to be there, and leave that to regular windows MFC drawings.
I know there should be away to do it with clipping. But since whatever is in that rectangle isn't drawn with the openGL I'm not sure that will work well.
I'm using openGL with c++.
Solution:
If you are drawing over unrelated windows, you should use Stencil buffer.
This can be used as a masking layer to decide where you want to draw.
If you have an MFC window with a child window, you can create the "father" window with the following style: WS_CLIPCHILDREN

Windows regions and transparency

I have a CDHTMLDialog in a BHO that I want to be partially transparent, in the sense that the transparent area changes according to the logic of the dialog. I got it to become transparent visually (using SetLayeredWindowAttributes), but it is critical to make this region truly transparent, because otherwise when I click on the transparent region my clicks do not reach the IE window which is below the transparent part of my dialog. I temporarily fix this by constantly resizing my dialog according to the size of the active part of the dialog, but I can't keep up with this forever...
I think the solution has something to do with what windows calls "regions" (http://msdn.microsoft.com/en-us/library/dd162915%28VS.85%29.aspx) but I'm not exactly sure how to work with them. Can anyone point me in the right direction?
I don't think you want to make parts of your window transparent, what you want to do is (I think) set the window region (like you mention). Read the MSDN on SetWindowRgn() - basically you define a GDI object of type HRGN (if you're using MFC, CRgn) which described a surface of a certain shape, and eventually with parts cut out. Windows then considers only the 'region' that you set on a window as the part of the window to use. Basically it's how you make non-rectangular windows. A 'region' isn't a 'transparent' part of a window, it's a way to discard areas of a window, in a way.
I found the way to make an entire window transparent and click-through here:
http://www.codeproject.com/KB/wtl/transparent.aspx
But it's not useful for my case where I only want the transparent part of my window (transparent by HTML/CSS definitions) to be click-through...
Update: Apparently, the clicks are supposed to go through the transparent parts (see http://jalaj.net/2007/02/05/form-with-a-hole/), but in my CDHTMLDialog they don't. My best guess is that a sub-window of the BHO catches my clicks, but I don't really think that makes much sense...

Creating custom transparent control

I am trying to create a custom control that displays a bitmap with per-pixel alphablend (as some of you already know for other questions).
Right now I am using a custom control in the resource editor and I attach it to a class derived from CWnd. When I register my custom class I set the hbrBackground of the WNDCLASS structe to NULL_BRUSH to achive the transparency of the control.
In the OnPaint of the control I use AlphaBlend to paint the per-pixel alpha blend bitmap.
This works quite well but I have this two problems:
I want to change the displayed bitmap when the mouse is over the control. As the control is transparent, the areas that one bitmap that are not overlapped by the other bitmap are not erased. How can I erase the background when the image is changed?
The second problem is related with two overlapping controls. My control is painted over other control that has a gradient (in fact is inside other control). The problem is that if I put my control before in the z-order the other controls overlap my control and mine is not displayed. If I put the other control before in the z-order I can not get the mouse message in my control.
Maybe I am doing something wrong or I am wrong in how I am trying to implement my control. Any kind of help would be appreciated.
Thanks,
Javier
I'll take a chance. :-)
This should give you all you need to accomplish what I think you want.
General Solution for Transparent Controls
As far as Z-order issues, the z-order does not affect message priority. You'll need to post some code so we can determine what is happening there.