C++ MFC How to draw selection rectangle? - c++

I have a list control. I want to draw selection rectangle on my own.
For example: when i clicked on an item it will draw an selection ractangle on that item and the item is next to it (or can be somewhere else).
Can anybody tell me how to do that ?
Thank you!

To draw a focus rectangle, call the DrawFocusRect function. To enable Visual Styles, call the DrawThemeBackground function (Parts and States: LBCP_ITEM and LBPSI_SELECTED).
Either way, you will have to create an owner-drawn List Box to be able to adjust rendering. For an MFC CListBox control you have to override at least CListBox::DrawItem (and usually also CListBox::MeasureItem).

Related

How to implement box selection in Qt?

I am trying to implement a selection box in Qt:
When the user holds down LMB and drags, a rectangle is created and drawn real time to the screen. I also want to be able to select on only one dimension.
I think overriding the methods QWidget::dragEnterEvent(QDragEnterEvent*), QWidget::dropEvent(QDropEvent*) may help, but I don't know how to dynamically obtain and draw the rect.

How to disable ListView select visual effect and draw a rectangle around item instead?

When a ListView item is selected, its color changes to indicate that it is selected. Now what I want to do is to disable this visual effect and implement my own, so for example I want when an item is selected to draw a rectangle around the item.
How can I do that? (Note that I am talking about the Icon view).
This is a case for custom drawing of controls.
It's all about handling the NM_CUSTOMDRAW notification and then to draw the control more or less by yourself.
I've never done it by myself changing the appearance seriously but I've change background colors of controls using this mechanism.
There is a lot of information about this on the internet...

Button in MFC CtreeCtrl column

I have a CTreeListCtrl in my MFC application.What I need to do is add a button in a particular column of a node when a particular condition is satisfied(type is changed to reference).
In the image I have edited and added a blue rounded oval to mark the place of desired button.What I want to do is to invoke a dialog on clicking it.But I don't have any clue whether it is possible or not.If yes then pls give me some suggesions.
This is no normal tree control. It is already customized to use multiple columns and I am sure it uses some kid of owner draw. For me it seams more like a list control with tree Features... I know some similar code from Codepproject..
Creating a "real" button (window) isn't wise/good. because it is another window inside the list control...
Change your code to "Draw a button. You can use DrawFrameControl.
Just intercept the left mouse click. Check the range if this area is cliecked. Fire a user defined message to the parent window.

CListBox item background

I need to set background CListBox background.
I can't find solution for set different colors for each item.
How can I do that?
To get different colors for each item you have to owner-draw the list box. That means you must paint each item yourself. See the CTRLTEST sample in MSDN.

Displaying a popup widget in QT over application border

Let's say that I have an application frame, and I want to show a popup QCalendarWidget over on the right side of the frame. Normally, QT will clip the edges of the QCalendarWidget, cutting it in half and not displaying the rest, as it would be over the right side border.
Is there a way to work around this limitation without resorting to implementing a QDialog?
I want the widget to be visible outside the bounds of it's container.
If you'd show your Calendar, let's say, after a button click, as QDateTimeEditor does, it's contents will not be clipped, cause it do not belong to frame. It will be just a widget, that shows in a dialog manner. And maybe you should even place it in QDialog, that is modal and provides some convenience methods, rather then simple QWidget.
Btw, why don't you want to use QDatetimeEditor?