JavaFX: Textarea background color error - css

Here's the problem:
I tired to make the textarea from javafx have a black color, so i tried to add the parameter:
"-fx-background-color" with the value "black"
It did change something: Around the text area a black border appeared. I tried to change the background size with:
"-fx-background-insets" with the value "100" (for testing purposes, i know there are up to 4 values)
But nothing visual happend.
However, if i set the value to "-100", the screen 100 pixels outwards of the textarea is painted black. So, in theory, reversed parameter delivers the reversed result of what i want.
Therefore i ask: Why is it not working? I looked up other solutions, and they do it with the "-fx-background-color" parameter, so what a i missing here?

Use the following in an external css file:
.text-area .content {
-fx-background-color: black;
}
don't forget to include this css file, either through FXML or through code. You can use this tutorial.

I just found the solution to change the color of the background of TextArea in JavaFX. Write this in your controller class:
textarea.setStyle("-fx-control-inner-background: black;");
I was deep searching on the stackoverflow and eventually found it. The link is given below: Textarea javaFx Color
Happy coding!

Related

How to change the highlight colour of a button in javaFX while maintaining its default look

firstly I'm sorry if this is a relativly basic question or a question that has been asked before, but I'm struggeling to find a good way of wording my question.
I'm currently working with JavaFX and a .css file to set the style globablly for certain elements. Currently I'm struggeling with working out how to change the colour of the blue highlight on the "Okay" button, as shown in the image below.
The highlighted blue colour only appears on the "ok/confirm" buttons of dialog windows. I should also clarify that the red outline in this image is done by me.
I tried numerous solutions, but none of them worked the way I wanted. The closest I got was with the following code:
.button:default:hover:pressed,
.button:focused {
-fx-background-color: rgb(238, 232, 232);
}
This did did however create a flat coloured button (and also when clicked it still changes to the blue-ish colour), while I would like to stay close to the default look.
I would like this highlight to be of a different colour, but I want to maintain de "default look" of the button, i.e. the same dropshadow, gradient style etc. How would I do this using css?
In the default stylesheet, modena.css, the color for a default button is defined using the "looked-up-color" -fx-default-button. (It is used as -fx-base for default buttons.) You can simply globally redefine that color:
.root {
-fx-default-button: rgb(238, 232, 232);
}

How can I remove drop shadow from menu items?

Problem
I have a MenuItem that by default is initialized with drop shadow—which I’d rather not have. I’ve got a css file set up, but can’t seem to figure out what’s necessary to remove the drop shadow.
See how there's a rather ugly drop shadow down below that? I'd like the whole menu button to be flat, containing no borders nor shadows whatsoever.
The reason the background color of the various different elements in the image are red is due to my attempts in styling it differently—the background color does indeed work the way I’d expect it to.
What I’ve tried so far
.menu-item
{
-fx-effect: null;
-fx-drop-shadow: null;
}
Neither one of the properties seem to effect the outcome of my program.
I've also tried styling the menu, but that only appears to style the actual “Plugins” button.
Moreover
I can’t seem to think of any better solutions compared to those I’ve already tried. Perhaps someone can point me in the right direction?
Once again, I’m attempting to make the menu items look flat.
You need to add the effect to the context menu, e.g.
.menu-bar .context-menu {
-fx-effect: null;
}
BTW: There is no -fx-drop-shadow property.

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; }");

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

color of QPushButton or QToolButton

I am using a Qstylesheet to control the behavior of some QPushButtons and QToolButtons. When I hover over them, they turn black, as I want them to. However, once I press them, they turn a funny greyish reddish color, and there is a red box drawn inside of them.
What is the property or pseudo state that I have to set in order to avoid this behavior? I have been through all the properties related to selection, and background, and cant get this to go away
Without seeing your style it's a little difficult to fix your problem. So what I'll do is explain a little how things work, and hopefully you can decide how best to address your problem.
First, it's important when your styling your button to ensure that you cover all your bases. I'm sure you know most of this, but just in case...
A QPushButton and QToolButton have a number of states that can be styled, so you want to make sure that you make your button noticeably different for each state so that the user can tell the difference.
QPushButton
{
// The default look of your button
}
QPushButton:disabled
{
}
QPushButton:pressed
{
}
QPushButton:focus
{
}
QPushButton:hover
{
}
QPushButton:checked
{
}
Use things like the background color, foreground color, border color, and generally you are good to go.
background-color: red;
color: white; // foreground color
border-width: 1px;
border-color: black;
The second thing to know is this, styles can be inherited. So be really careful when you add a style to a widget. When you create a style try to be specific. If you give this style to something in your UI, the background color will be blue, but the dangerous thing, is that all child widgets of this one will also inherit this style.
QWidget
{
background-color: blue;
}
Maybe that's what you want, but often not. So if you are styling buttons always put the QPushButton or QToolButton selector around them, the same should apply for other things you are styling too. So it's possible that's where your greyish reddish color is coming from.
Now, the last thing to know about styling buttons is the focus rectangle. It is the irritating dotted line that appears when your button has been focussed. See the picture below.
The unfortunate thing is that there is there is no way to style the focus rectangle using style sheets. But you can get rid of it, if that's what you want. See the following link:
Getting rid of the focus rectangle
So, in summary...
Make sure that your button style covers all the states that you
need.
Make sure that your button isn't influenced by any other
styles you have added to other widgets.
Either change, or get rid
of the focus rectangle as needed.
I hope that helps. If you want more specific help, then please post your style, and I'll take a look at it.

Resources