Remove Focus Box Around TextField - javafx

Using JavaFX when I create a TextField and set
numberField.setFocusTraversable(false);
and then click on the field the blue box shows up around it. I guess that makes sense
but there is no
setFocus(bool)
command.
I want to get rid of the box. Any suggestions?

The setFocusTraversable(false) disables the focus traversing (by TAB and SHIFT+TAB) for that node. Thus it has nothing related with node's GUI style. To hide the focused blue color do:
Via code
numberField.setStyle("-fx-focus-color: transparent;");
or via css file
.text-field {
-fx-focus-color: transparent;
}
or pseudo class in css file
.text-field:focused{
-fx-focus-color: transparent;
}
-fx-focus-color is not a css property, it is a predefined color of caspian.css (JavaFX 2).
This answer is related to and referenced from: How do I remove the default border glow of a JavaFX button (when selected)?.

Related

How do I change the header color of a TabPane in SceneBuilder?

I want to change the header color (the grey one) on SceneBuilder. I've tried changing the background but it only changes the frame, not the top of the tab.
I'm kinda new into JavaFX and CSS, so I don't know how to change it manually with CSS. Here's what I want to change:
I want to change the gray bar to blue.
You can change the header background for the TabPane using the appropriate CSS selector:
.tab-header-background {
-fx-background-color: blue;
}
Result:
As far as I know, the only way to have the new style show up in SceneBuilder is to create a .css file with the code above, and then import it into SceneBuilder for your root element (for instance, a top-level AnchorPane):

QT Tab bar's top highlight with stylesheet

I have a problem when trying to change the color of QTabBar's top line (blue line in the picture below).
Is this a separate part of tabBar (like scroller or tear) or its top border ? And how can I change its color with styleSheet and leave the other parts of tabBar unchanged?
P.S. : My tabBar::styleSheet returns an empty string, so I can't get current style and make changes in it.
If you're using a "system" style, you may not be able to change the color of the line (cause representation of UI elements is not handled by Qt but by the system).
You should define a complete style for QTabBar (and maybe QTabWidget too) that you can customize as you wish.
See the Qt Style Sheets Examples page.
Problem solved:
setStyleSheet("QTabBar::tab:selected { selection-background-color: red; }");

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.

How to prevent the default blue border being drawn on QLineEdit focus

I am trying to achieve a borderless QLineEdit through CSS. It works fine when the QLineEdit is not in focus but when in focus the default blue border always comes up. The simple CSS I am using:
QLineEdit, QLineEdit:focus { border: none; }
I have tried with different background color through CSS for focus and not-in-focus, it works but I am unable to remove the blue border while in focus. Just to inform, I am working on a Mac.
You might get rid of the focus border by setting:
QLineEdit.setAttribute(Qt::WA_MacShowFocusRect, 0)
Read the documentation, there are plenty of other Mac specific settings
WidgetAttribute-enum
There is rather a similar question too
Refer this question
Maybe also like this way:
ui->treeView->setAttribute(Qt::WA_MacShowFocusRect, 0);
Reference: http://doc.qt.digia.com/4.6/demos-interview-main-cpp.html

Qt style sheet properties for toolbox buttons

I want to give some color to the area where they are toolbox buttons with icons (light grey on picture). Please help in determining what is a parameter style sheet?
If I understand correctly, you are trying to change the background color of the toolbar area.
Suppose I have a mainwindow with a toolbar called mainToolBar. Here is what I did :
ui->mainToolBar->setStyleSheet("QWidget { background : red; } QToolButton { background : green; }");
The first part of the stylesheet will change the background color of the toolbar where there is no toolbuttons.
The second part of the stylesheet will change the background color of the toolbuttons.
Note : I tested the code snippet above on Windows, I suppose it should work on a Mac too, but I cannot guarantee.

Resources