Selected objects on Mac show background highlight instead of bounding rectangle highlight - c++

I have a Qt application that I am porting to mac.
There are some objects (images) shown in QListView or QTableView, in IconMode, that, when selected, in Windows and Linux get highlighted (a rectangle holding the object, which has colored background - gray if the item is selected but no focus, light blue if the item has focus, slightly more intense blue if the item is selected and has focus - this is probably the default behavior for selection, based on selected color scheme).
On mac the only thing that shows is a tiny dot under the object, and if the object in the view is transparent, light blue shows inside the object - but no selection rectangle. Nothing changes if the object has focus, and if the object is not transparent, only the tiny dot under the object shows.
Once objects are moved on the canvas, mac shows selection as needed, on a bounding rectangle, only inside the listview and tableview the bounding rectangle is invisible.
The form was created using the Designer... the listView property QListView.selectionRectVisible is checked.
I can't see what makes that happen... but I have tried
#if defined (Q_OS_MACX)
m_ui->lv1->setAttribute(Qt::WA_MacShowFocusRect, true);
m_ui->lv1->UseCustomSelectionColors(true); // documentation shows this but it doesn't build
m_ui->lv1->setSelectionRectVisible(true);
#endif
for the mac, and it does not make any difference.
What else can I try, to show selection of objects ?
Qt 4.8
Edit: found a site that has an example for a tiled list view... among other things it draws a visible rectangle around the selected items...
It seems like a very complicated way to do something that seems to be already implemented - highlighting a selected object - I will do it if I have to but I am hoping that I do not have to add something too complicated for the mac version, that will not be used in any other platforms...
There has to be a way to use the normal properties and methods of listview and tableview to make sure that the background of the bounding rectangle, not just the background of the item, shows when a selection is made ?
I don't know if this is a typical mac behavior...
Update
While I really try not to overwrite the desired default system behavior, I tried to force list behavior...
#if defined (Q_OS_MACX)
QString stylesheet = "";
stylesheet += "QListView::item:selected:active:hover{background-color:red;}";
stylesheet += "QListView::item:selected:active:!hover{background-color:blue;}";
stylesheet += "QListView::item:selected:!active{background-color:yellow;}";
stylesheet += "QListView::item:!selected:hover{background-color:green;}";
setStyleSheet(stylesheet);
#endif
The problem is, I need the system colors, I cannot define my own since they will not match the rest of the app window...
What are the names of the system colors for hover, select (strong), select (but no focus), select (but not active) ?
I have tried using
stylesheet += "QListView::item:selected:active:hover{background-color:Highlight;}";
In windows, this looks ok - because it probably is not recognized so it is ignored... On mac, still ignored. And I have not seen any other names for backgrounds. I tried it with lowercase as well.

I ended up using a style sheet - as in the update to my question - with hard-coded color values for the osx blue theme.

Related

RectangularGlow with Qt 4.7 without QML

I'm working on some Qt GUI application with shiny glossy design.
I have a list view customized with my QItemDeleagte subclass. I draw items in paint virtual method. Selected items need to be drawn with glow effect on the border. Normal items must be without glow effect
That's RectangularGlow QML Type which is exactly what I need my view items border to look like. Unfortunately the app was written in Qt 4.7 and there is no way to port the app and all its dependencies to Qt 5.
QGraphicsDropShadowEffect is not sutable since shadow gradient has one direction and an offset. QLinearGradient doesn't help too or I don't know how to use it.
I consider drawing some kind of border image.
Is there any proper and elegant way to implement this using gradients or graphics effects?
EDIT:
As cmannett85 pointed out QGraphicsDropShadowEffect seems to be ok. However graphics effect may be installed on a whole paintdevice and for view item i cant just draw only selected item border rectangle with glow effect and leave other elements in a normal state. Instead all drawing on a list view affected
EDIT2:
I found a solution in an answer for another question. So I think this question may be closed

Grey out items in disabled ListView

I am writing an application in C++ using WinAPI.
I have a ListView of items with checkboxes and a scrollbar. Sometimes I need to disable the whole thing. When I call EnableWindow() to do that, the behavior of ListView is ok. It gets disabled, none of the contents are accessible any more. However checkboxes and scrollbar still look normal (not grayed out as the rest of the element).
Is it possible to grey out all parts within the ListView?
Enabled
Disabled
Normal disabled checkbox looks liks this: <- this is how I would expect to see checkboxes in the ListView, same applies to the scrollbar.
Regarding the checkboxes, the documentation for LVS_EX_CHECKBOXES says:
When set to this style, the control creates and sets a state image list with two images using DrawFrameControl. State image 1 is the unchecked box, and state image 2 is the checked box. Setting the state image to zero removes the check box.
You can therefore just change those images at indices 1 and 2 in the image list to their properly disabled variants when you are disabling the whole control.
The process itself of course varies depending on the framework you are using (if any), but generally will be along the lines of creating an Image List of SM_CXSMICON×SM_CYSMICON icons, creating a bitmap (2*SM_CXSMICON × SM_CYSMICON) pixels big, selecting it into a Memory DC for drawing, calling DrawFrameControl(..., DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_FLAT | ..., ...) twice as appropriate, then using that bitmap in the Image List (and saving the previous IL to restore when the window is enabled again).
Regarding the scroll bar, you cannot get access to the implicit scrollbar as a separate window, so I don't think you can easily make it look more disabled without resorting to more custom drawing hacks for the non-client area of the List View.
Or creating an explicit scroll bar control yourself, but then you need to make sure it behaves the same as the original one, changes when the list view items change, respects right-to-left locale and so on.
It might be a bit of a challenge to get all the offsets and possibly transparency right even for the custom checkbox images described above. Even though this is how the List View control itself does it, it might not be worth the effort in the end.

How to change button color?

I am developing a GUI application using Embarcadero VCL c++ IDE for windows OS. As part of this project, I have to change color of button with respect to an external state.
I understood that windows32 API will not allow to change the color of button.
Could you please suggest me, how to change button color?
Do you wish to change the background-colour of the button, or the text-colour of it?
Since windows has used visual themes for some time now, if you have commctrl loaded and include a manifest file, the button will be drawn using the default (current) theme.
Options I can see include (a) custom-drawing the background (b) changing the text-colour in the normal draw process (c) drawing the button without a theme (i.e drawing a 'flat' button).
You could simply draw a bitmap-button, changing the bitmap depending on the state of the button. You could also use a single bitmap, tinting it using the HSL or HSV colour-space, depending on the state.
As for the flat type of button, I think you can probably change it's background-colour in much the same way as you can change the colour of the text - by intervening during the standard draw process and changing the colour from 3D_FACE (or whatever it is, I forget) to whatever you'd like.
If you look at the calculator included with windows XP, you can see an example of changing the text colour.
CodeProject.com likely has a stack of articles that would help in this endeavour. :)

Avoid truncation of Labels in a ListView

folks!
I use a listview (Icon mode) to display items which consist of an image and a label.
As you can see in the shots the row height is variable on y depending on the label length. The problem is that I want the complete labels to be drawn, but they are automatically shrinked into two lines:
The strange thing about it is that once you select an item the whole label will be shown:
This is also the case when deselecting the item, but when another item gets selected, only that one will be shown completely.
Is there a way (without drawing the text manually) to avoid truncation in my case?
If some code is needed to answer this question, don't hesitate to ask.
Greetings,
Satara
I'm guessing this was a design choice: make things look less cluttered. E.g. picture your desktop with all labels shown completely... will look messy in my case.
However, you can fix this by drawing the label yourself. Have a look into custom draw which is a service provided by the list control. The thing is that it's usually an all or nothing approach, so this will likely require you to draw everything yourself: border, image, label, etc. The other option is to get hacky: subclass the window and draw the labels again after Windows did in response to several messages (unfortunately Windows does not restrict the painting to WM_PAINT, an optimization that is a left-over from the old days...)

swapping background colors in gtk text field (gtkmm C++)

Within my GUI (C++, GTKMM 3), i have a text field that is providing some status information. i'd like to change the background color of this field (along with the text, which i can easily do), based upon the status.
there's not a lot out there on how to do this with GTKMM 3.X. i know i need to use the CssProvider class, and have found some examples on how to load one into the program. but the examples show how to set the properties one time.
but what i haven't figured out is how i can use the CSS properties to change the color of the background, based upon a state (not a state as in 'hover' or anything like that. i want to be able to swap the background from red to green whenever i please). if the CSS is written in terms of using the name of the widget, or the type of widget, how do you handle a changing state with the widget to change its properties?
if anyone has any clues, or knows of any examples, i could really use some help. the purpose of this is to give the user some immediate feedback at a glance. in a rush, they won't have to read the status of the box (or from a distance). the color will allow them to gauge what is going on at a glance.
Adding code
this is what i have tried so far (condensed):
std::string style_sheet = ".red_bg {background: #FF0000; color: #000000; } ";
style_sheet += ".green_bg {background: #33FF33; color: #000000; }";
Glib::RefPtr<Gtk::StyleContext> stylecontext = my_text_field->get_style_context();
Glib::RefPtr<Gtk::CssProvider> cssprov = Gtk::CssProvider::create();
cssprov->load_from_data(style_sheet);
stylecontext->add_provider(cssprov, GTK_STYLE_PROVIDER_PRIORITY_USER);
stylecontext->add_class("red_bg");
stylecontext->context_save();
so that works. when the program fires up, i get a text entry with a red background.
but later on, if i do the following, nothing happens:
Glib::RefPtr<Gtk::StyleContext>stylecontext = my_text_field->get_style_context();
stylecontext->remove_class("red_bg");
stylecontext->context_save(); // probably not necessary
stylecontext->add_class("green_bg");
stylecontext->context_save();
at that point, the background stays red. no transition from red to green. i've seen suggestions to use the override_background_color function in the GtkWidget object, but that doesn't work. that only changes the color that is used when you highlight the text in the widget. i'd still like to see it done the CSS way.
You could do away with the CSS and just use override_background_color, a standard GTK widget method:
override_background_color (StateFlags state, RGBA color)
Sets the background color to use for a widget.
All other style values are left untouched.
Note:
This API is mostly meant as a quick way for applications to change a widget appearance. If you are developing a widgets library and intend this change to be themeable, it is better done by setting meaningful CSS classes and regions in your widget/container implementation through add_class and add_region.
This way, your widget library can install a CssProvider with the STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a default styling for those widgets that need so, and this theming may fully overridden by the user's theme.
Note:
Note that for complex widgets this may bring in undesired results (such as uniform background color everywhere), in these cases it is better to fully style such widgets through a CssProvider with the STYLE_PROVIDER_PRIORITY_APPLICATION priority.
Parameters:
StateFlags state the state for which to set the background color
RGBA color the color to assign, or null to undo the effect of previous calls to override_background_color