Make Default Buttons Look Like Normal Buttons - css

I have a JavaFX button that has been set as Default Button so the user can select it with the Enter key. Currently, it has a blue background:
But I'd like to make it look like a normal button:
I took a look at the JavaFX CSS Guide and it looks like there's only one feature to override (-fx-base).
But changing this feature has unpredictable effects—sometimes it eliminates the button's gradient; sometimes it makes the button transparent.
Is there a simple way to just get rid of the Default Button styling?

My guess is that you are looking in the wrong style sheet. The old default style sheet caspian.css was replaced with modena.css. So setting default value for -fx-base from modena.css should fix the issue:
.button:default {
-fx-base: #ececec;
}

Related

Dynamically change JavaFX properties for specific classes in CSS

I am writing code that allows a user to build a theme for the application, so they need to be able to effectively communicate that they want to change something about some element of JavaFX.
Suppose I have a bar on the top of every view that lets a user change the way some set of things look: button, label, text, and so on.
Here is a basic stylesheet that I am working with. It just puts style on root and button.
basetheme.css
.root {
-fx-background-color: "teal";
}
Button {
-fx-background-color: "orange";
-fx-font-size: 2em;
-fx-text-fill: #0000ff
}
Right now, all the views I have would load this sheet each time they are loaded:
view.getStylesheets().add("views/basetheme.css");
The Button class and its fx properties here would apply to all buttons in the view.
This is the behavior I want. I want the user to have leverage over Button and its properties during runtime.
For instance, if they want to change Button's -fx-font-size property from -fx-font-size: 2em to -fx-font-size: 3em, they can do that. Is this possible?
Currently, I know setStyle will set properties on some elements, but I am looking for a way to do this for not just a single Button, Label, and so on, but for all them. I want there to be run-time changes. For instance, after a user changes some element like button and one of its properties, it reloads that view and the change is applied.
I want to do something like view.setStyle("Button: some properties") and then it add those properties to Button class or overrides it, instead of view.setStyle("some properties") adding properties to root. The latter would not recognize that the property goes on a button, let alone all Buttons in view.
The obvious reason why this might not work this way is that we are not really changing the css file when we do those inline setStyle calls, just setting over the existing property and thus that inline has higher precedence and is updated.
I know I could technically do somebutton.setStyle("some properties"), but I want the user to be able to modify properties for all Button elements by specifying it at the root of a view so the styles trickle down to subelements in the view. This makes things easier.
You could use CSSFx to constantly pull in a CSS file that has bee written by your app.

Javafx CSS values in code

Simply put, I have a JavaFX Textfield that I wish to 1) change the text color on, and 2) change it back to that specified in CSS. Does anyone know how to (generally) access css colors etc. from within the JavaFX code?
AnyFxElement.setStyle(String elementCss);
For source of all the css capabilities I reccomend looking up caspian css.
To remove a style use the code:
// remove the background color on the button
yourElement.setStyle(null);
To set it back to it's default style:
// set the button style back to the default class
yourElement.setStyle(".yourStyle");

CSS: Style a text link in a class

This is a most basic question about formatting text links in css
I have tried to do it myself. I got the hover to work -- at least in firefox. But can't get the default color to work. Only hover.
Please look at this development page http://ogrowby.com/ in firefox.
There is a menu about the middle of the page, called "Test Menu". Please click on that. Then, in the dropdown, go to "TEST LINK".
When you hover over it, the text color changes to Gold. That is fine. But its default text color is black and I want it to be white. I may also want to change the font size, etc. But the main thing is to get the css working to set the default text color for this class to WHITE. #ffffff.
Here's my css so far. The hover is working, but the default remains needs to be changed to #ffffff Only for the .roundedblue class. And it needs to work not only in firefox but other modern browsers.
Any help will be appreciated. Thanks
Rowby
.roundedblue:link,
div#Maximenu_NEW_GRANDE ul.maximenuck2 li.roundedblue:hover span.separator {
color: white;
}
.roundedblue:hover,
div#Maximenu_NEW_GRANDE ul.maximenuck2 li.roundedblue:hover span.separator {
color: #FFB300;
}
If that is the only link you want to change, you should add an id to it and change the id's css properties. If you want multiple elements to have the same properties add a class to the element (if it doesn't already exist).
Then simply edit its properties as you would normally.
color:white;
font-size:14px;
...
I simply changed the styles in inspector and it worked for me. added "style='color:white;'" to your span.

Make disabled Flex Spark Button more readable using CSS

I have a Flex Spark Button that I've changed the background to a dark color using
s|Button {
color: #66ffff;
chromeColor: #333333;
}
The problem is that when the button is disabled, it's very hard to read (the text color and background color are very close). I've tried setting the disabled color to something lighter
s|Button:disabled {
color: #ffffff;
}
But the disabled text's color is not #ffffff. It's some combination of the text color and the background. Is there someway to disable this behavior (ie, specify the exact disabled state's text color)?
You are battling with the default skin of the button. If you were to create a new button skin based on ButtonSkin, you would see that the alpha for the entire skin is set: alpha.disabled="0.5".
Setting the value to 1.0 solves your problem, but it seems overkill to define this entire skin just to modify this single value.
Hopefully, there is a more elegant way. I tried setting alpha: 1.0; in the disabled style, but it doesn't take. The only thing I have been able to do is create a new button style, set alpha.disabled="1.0" and telling the button to use that slightly modified style.
You can create 2 .css files, one for the standard view and one for the "disabled" view and set your own button properties. Write a function which changes the .css file to use.

Styling QPushButton with CSS?

I'm trying to create a QPushButton that's just got an icon and a constant background color.
So that I can swap out the icon when the user clicks it, without any other apparent effects (this is for a roll-up/roll-down feature). I've added an entry like this to my stylesheet:
QPushButton.ToggleButton {
background-color: #8af;
}
and set the button's class to match, and this does indeed give me the look I want, except that when I click on it the background color changes to a lighter blue, which I don't want. What am I missing?
Edit: I guess I should mention I'm using Qt 4.5 and PyQt 4.6 to do this...
I know people like using stylesheets, but in this situation I think it is just as easy to make a custom button. Define a class that inherits from QAbstractButton, and override the paint() method. In the paint method, fill the rect with your desired background color, and then paint the current icon on top. It might be slightly more complicated if you want the border around the button as well, but not a lot.
Alternately, you could also look at the roles for QPalette, specifically QPalette::Light and QPalette::Midlight, which might be used to adjust the color of the button when pressed.
Answer
Try giving the button an ID with QObject::setObjectName and then applying the style with #idSelector?
In Python the code would probably look something like this:
button = QPushButton(self)
button.setObjectName("ToggleButton")
and stylesheet like this:
#ToggleButton:pressed {
background-color: #8af;
}
Further reading
The QFriendFeed example application at Forum Nokia is using Qt style sheets heavily to customize the UI.
I'm guessing doing background-color: #8af !important; would be too obvious so I'm assuming that doesn't work. It's worth a try if you haven't done it yet.
Otherwise, as noted in this question, there are specific states you can style. Try setting the same background color for the pressed state:
QPushButton.ToggleButton:pressed { background-color: #8af; }
Sorry if I misunderstood. Hope that helps.
open the button's stylesheet in Qt designer and try this:
QPushButton:pressed {
image: url(/path/to/your/file/fileName.png);
}

Resources