Clistctrl item text color - mfc

How do you change the text color of a Clistctrl item (report view)?

You need to handle the NM_CUSTOMDRAW message and change the text color in that handler.
For an example, see this article.

I would implement a CMFCListCtrl derived class and override the OnGetCellTextColor method. Things are much easier this way than with custom draws.

Related

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.

Handling dynamic text editing in an MFC CView

I have a class that implements OnDraw to draw text and images to a CView. At certain times (ie onClick) I would like this text to be editable in place. What would be the best way to implement this?
Have the class have a CEdit object that I hide and show and draw over
the top of my text.
Handle key presses in the class and implement my
own editing
Have something external to the class control whether to show the edit box or my class
Something else?
Go with your first idea, create a CEdit box when you need some text editing. If you look at how a ListCtrl handles rename functionality it does exactly that.

How can I make a dotted line separator in an MFC dialog?

Is there a control for this anywhere? Or a way to use another control to make it look like a separator?
Thanks
You want to use the image control and change the color property to 'Etched'. Resize the control so it just looks like single line.
Override the OnPaint function of your dialog and have it draw the line. Ordinarily the OnPaint for a dialog doesn't do anything, as all the content is in controls which paint themselves.

How to prevent an icon being highlighted?

I have a listwidget with items which have icons. When the item is selected both the text and the icon are highlighted. My problem is that when the icon is highlighted it just goes entirely black because I'm using only two colours. Is there a way to prevent the icon from being selected?
You can add additional images to the QIcon, depending on it's state:
QIcon icon(...);
icon.addFile("selected.png", size, QIcon::Selected);
See also the documentation of QIcon::addFile().
Best solution was to make your own qstyle which handled the painting of the backgrounds of listitem sub controls and draw the icons qrect as white
Another possibility would be to reimplement QListWidgetItem... You could therefore have a bigger control on how things gets done during the process of selection and painting...
Of course, it's a lot more work...

How to draw a progress bar inside a list widget in Qt

I want to have a list of items that need to be processed in a QListWidget. Similar to Windows Media Player CD import, there should be a progress bar for every item in the list.
Now there seems to be a way to do this by creating a regular progress bar, using QPixmap::grabWidget() to save its appearance in a QPixmap and then adding this QPixmap as Icon to the QListWidgetItem via QListWidgetItem::setIcon().
However, this seems to be horribly wacky.
Do you know a more elegant way to achieve a progress bar inside a list widget?
Each item in a QListWidget can be represented by a QWidget of your choice, rather than the default rendering (text). You can set this by calling QListWidget::setItemWidget(). In this case, I'd recommend using QProgressBar as the rendering widget -- you should get the desired result.
From the documentation of QListWidget::setItemWidget():
This function should only be used to
display static content in the place of
a list widget item. If you want to
display custom dynamic content or
implement a custom editor widget, use
QListView and subclass QItemDelegate
instead.
You could do it by converting your list widget into a model/view/delegate combo. Then you can set a delegate on the list view that overrides the paint functions and draws the progress bar wherever you want it. I don't know how easy it would be to get an actual QProgressBar widget into the drawing area, however.
Alternately, you could consider making your own list-widget like container that knows about the progress bars.