Issue with displaying the text colors of the items inside QCombobox - qt

I have a QCombobox, consists of 3 or 4 items.
Whenever,I try to select an item from my QCombobox, the color of the item changes to black(is not at all visible clearly).When I move my cursor away from the Dialog UI, then the color of the item changes to white (and is now clearly visible).
I think the problem lies with my QCombobox focus, but still not sure if I need to take care of it while adding the items inside my QCombobox.
Can someone explain the method, so that text of the items inside my QCombobox are clearly visible always?

Look for any stylesheets added for the combobox.
Also you can look for "setItemdata" function and anything is done with respect colors (backgroundrole).
Or if it is tough to figure out and wasting time, after adding your combobox items, change the background color of items to your convenience (Red in below code is just an example).
ui->comboBox->addItems({"text1","text2","text3","text4"});
ui->comboBox->setStyleSheet("QAbstractItemView { selection-background-color: red; }");

Related

Setting state for all children the same as parent

After trying to find a solution for Centering Text on a Button with Offset, I'm doing now a custom component.
The goal is to make a button-like component that has an icon on one side and a centered text filling the rest of the button.
The component contains either two Label/ Buttons to display the Icon and text. Both of them have a background Image, defined in css.
The css looks like this for Icon and the text with exchanged image as background for text
#button-icon-cancel{
-fx-font-family: "Arial";
-fx-padding: 0,0,0,0;
-fx-background-color: transparent;
-fx-font-size: 28px;
-fx-graphic: url('images/button/cancel.png');
}
#button-icon-cancel:pressed{
-fx-graphic: url('images/button/cancel-pressed.png');
}
The images are loaded by setId(). Currently both components are added to a Panel before passing to the stage. They contain an OnClickEvent for processing.
Now to the actual question
How can I achieve that if one Component is clicked, the other one is getting the :pressed from css as well?
Adding the ClickEvent to the Panel is doing nothing (regarding clicking on either Label/ Button)
Adding both of them to a HBox, adding the Event to the HBox work in that regard, that I can click either component and the Event gets fired, BUT the :pressed State is only applied to the component you clicked.
Is it possible to give all childs the notification, that they should behave like they got pressed? Since we have a lot of small Icon, but only one background for the text, placing a Label over the whole thing create a lot of unneeded wasted Image space. Also this would cause the problematic for changing font color if not all css are changed at once (the label-over-button-solution with .setMouseTransparent(true) wouldn't change the font color of the text label since the label doesn't notice button is pressed)
First of all, JFX-8 will support wider range of css improvements, which will allow you to solve the issue easier.
To solve your issue, i can suggest the following : each node have a pressed property. You can add a listener on this property, and when it changes to true, use setStyle(String) method on needed nodes, and use setStyle(null | "") on changing to false.

Highlighting text in JavaFx Label

I am trying to set the text background of the JavaFx label text as green using the following CSS
label.setStyle("-fx-background-color:rgba(85, 255, 68,0.7););
And the unhighlight using the following
label.setStyle("-fx-background-color:rgba(0,0,255,0);");
However these does not work most of the times when it has to be done back to back.
Is there any way to set the style without using CSS i.e. using JavaFx API itself. I found label.textFill(Paint p) for text color but nothing for background colour i.e. the color of the label itself.
Is there any way to set the style without using CSS i.e. using JavaFx API itself.
For some styles (such as the text fill) yes. For background colors, background images, borders, etc API methods will not be available until JavaFX 8 is released (see Public API for Region backgrounds and borders in the JavaFX issue tracker for more information - anybody can sign up for access).
these does not work most of the times when it has to be done back to back.
If you just highlight a label and then unhighlight it again without using something like a PauseTransition to give the user some time to see the highlighted label, then, from the user's perspective nothing is going to happen as all the user will see is an unhighlighted label.
Not sure of your use case, but if you only want to highlight part of the text in a label or let the user highlight the text with a mouse, then you can use a TextField with editable set to false.
Possible Workaround
If the Java 8 preview does not work for you and you are experiencing errors due do bugs in the JavaFX CSS processing, then try placing a Pane then a label inside a StackPane. Set the background color of the Pane to label.setStyle("-fx-background-color:rgba(85, 255, 68,0.7);); Bind the Pane's preferred width and height to the Label's width and height and toggle setVisible on the Pane as appropriate.
Finally I found the workarround. I had to give a PauseTransition to give the system some time between unhighlight and highlight. CSS showed effect only after the pausetransaction if the labels were already highlighted. I think it may be a bug. I will file a jira. The duration of paustransition may be as low as 1 milisecond so that there is not lag from the user's point of view.

QRubberBand Selection - Stopping dotted line around selected items

I am selecting items using the default QRubberBand enabled by setting QGraphicsView.setDragMode() to rubber band selection. This works fine, however when an item is selected it appears with a grey dotted line around it's bounding rect and I was wondering if there is any way to prevent this?
It appears the only way to do this is to override QGraphicsItem::paint().
The default implementation of paint() for standard items will change the pen if the item is selected or not. But since standard items likely consist of 1 line paint() calls changing this is trivial.
For example in a QGraphicsLineItem it would just be painter.drawLine( line() );

Displaying a QStandardItem with its foreground color in a QTreeView even when it is selected

Using Qt 4.6.3 on Linux/X11.
I have a QTreeView widget which uses a QStandardItemModel as its model, with 4 columns and hundreds of rows. Most of the items in the list are to be displayed with a standard color, but a few need to be of a different color. I can change the colors of those few items easily with QStandardItem::setForeground().
However, that only affects the color of the item when it is not selected. When I select a colored item, its background color changes to blue (which is ok), and the text color changes to white (which is not ok). I tried using a stylesheet to affect the foreground color of selected items (with selector QTreeView::item:selected), but it affects all items.
I would like items for which I called item->setForeground(Qt::red) to remain red even when they are selected, and other items to use the default set of colors (which they already do). How can that be done?
The colors being used are (I assume) those for the QPalette's Hightlight and HighlightedText roles. Unfortunately, I don't know of any way to set those on an individual standard item.
However, since standard items are used in the model/view framework, you have another option. You should be able to create a delegate to paint the view however you want to. I would recommend inheriting from the styled delegate, and calling the parent class's functionality as much as possible. Likely, you'll only need to change a few parameters in the cases where an item is selected and has a non-standard foreground color.

Flex 3 - Custom tab navigator

I'm trying to create a custom tab navigator that has to look like this http://www.freeimagehosting.net/uploads/b470d024c4.jpg.
Also, when there's a rollover, the borders of the arrow have to be in blue (like the label in the current tab).
For that purpose, I've created a custom component: a hbox containing a label and a canvas with 3 images inside (for the arrow tip that has to change depending on the currentState).
Then, I thought of overlapping the components in order to get the blue highlight color (ex: arrow button 3 is over arrow button 4. The image of the arrow tip in button 3 will be transparent outside the arrow, so that we can see the black color of the following button).
I'm now trying to position the components inside the canvas ... but I cannot.
After the creationComplete event, I assign the label text and I was calculating the coordonates of the component but it doesn't take into account the label width... -_-'
Any ideas?
Thanks. Regards,
BS_C3
Read up on the Flex Component LifeCycle. You should be positioning and sizing your child components in the updateDisplayList() method; not in a creationComplete handler.
You should assign the label text in either commitProperties or createChildren depending upon when you know what it is.
If you want to share some code, we may be able to hone in on the exact problem. If you run code like this:
myLabel.text = 'Blahblahblahblah';
trace(myLabel.width);
I would expect that the width has not changed to reflect the new text because the myLabel has not gone through it's own component lifecycle steps yet.

Resources