I'm using a QwtPlot to draw some data in a fairly heavily styled application. I'm using QtCreator as an IDE, and load one stylesheet for the whole program at the start to keep a consistent look and feel across the whole thing using
qApp->setStyleSheet(style);
All the built in controls obey the style I set here, except for my QwtPlot. Currently all I'm doing in the style sheet is trying to set the foreground colour to white with
QwtPlot
{
color: white;
}
But it doesn't work. However, if I specifically chose "set style sheet" on the widget the designer in QT creator, and just put
color: white;
it works.
It seems to me as if the plot isn't inhereting the top level style sheet, or for some reason my naming/syntax is wrong for selecting the plot (though the few references I've found to styling a QwtPlot online do use the same selector as me).
Can anyone help?
Related
I use ready-made Angular components in my project. Some of the components use colors (see picture) that don't fit my project.
Instead of the purple, I want to use another color. I couldn't find anything in the Angular documentation to change the color.
https://material.angular.io/components/input/overview
I also didn't see a property in Chrome's Inspecter Tool to change the color.
How can I use a different color instead of the purple?
It would be best if you only have to change it in one place, as I use many other Angular components.
If you check the CSS for the placeholder text in the browser inspector, you should see the associated CSS that you should be able to copy to your code and change. Below is what I copied when I went to https://material.angular.io/components/input/overview and inspected (and even changed). If you decided to add this CSS as is to your Angular app, be sure to change the encapsulation option to ViewEncapsulation.None to see the effect. This is if you're using Angular Material v15; otherwise, inspect and see the associated CSS.
.mdc-text-field:not(.mdc-text-field--disabled) .mdc-floating-label {
color: orange;
}
I use C++/Qt 5.12, Windows 7 OS, Visual Studio 2017.
I'd like checkable QPushButton background to ignore checked/pressed state. I'd like to have a default background in a QPushButton instance, but only font color should be changed if the user checked the button. How can I achieve this effect?
You can use QSS (CSS with Qt's flavor) to customize QWidgets:
https://doc.qt.io/qt-5/stylesheet-syntax.html
I would recommend creating an application-wide QSS that you load at startup, and use QApplication::setStyleSheet(...). But you can use Qt Designer (right click on a specific control), or plain C++
myButton->setStyleSheet("QPushButton { background: yellow; }");
You may need to redefine border to have it visually applied, and then margins to have a correct button size, but it is fairly easy. Try experimenting from Qt Designer.
You can find a comprehensive reference of all selectors and attributes available here: https://doc.qt.io/qt-5/stylesheet-reference.html
I've just started learning GWT so my question might be noobish. Tried to find a 'standard' solution but couldn't find it.
I'm developing an AddressWidget. It is implemented as a Composite widget which consist of atomic widgets (Labels, TextBoxes, ListBoxes...) defined in AddressWidget.ui.xml. These tiny building blocks should get their CSS from the common-widgets.css. The AddressWidget itself should get the default styles from address-widget.css.
As this widget will be used on different pages, they should be able to override the styles applied in order to customize the appearance. I.e. the OrderPage should apply its own from the order-page-address-widget.css, the ContactDetailsPage – from the contact-details-address-widget.css
How do I implement that?
My advice - drop this idea. It will be hell to develop and maintain, and I mean it. You will constantly try to figure out which CSS file has to be updated, and then you will have to test every update in multiple places, because an update in one file can mess up with CSS from another file.
Many GWT developers prefer to use CssResource approach to CSS. I've never heard any designer favoring this solution, though.
After years of working with GWT on both the code and design sides, I strongly prefer to use a single CSS file for the entire application. CSS was built for inheritance, and this is what a single file achieves. You can define basic style, like:
input {
height: 24px;
}
If you need to change these styles in specific widgets or parts of the application, you can set, for example, "contacts" class on the contacts page/widget, and then add this to your CSS file:
.contacts input {
background: grey;
}
The advatantages of this approach:
easier to enforce consistent look throughout the application
easier to maintain your CSS, because there is one file to update, and there are no conflicts with CSS defined anywhere else
it is an approach that most designers understand and know how to use
it is the easiest solution if you want to create multiple skins or themes for your application
it is easy to make your CSS adjust to different screen sizes, or define special styles for printing.
I've read the documentation thoroughly and searched the familiar domains like google and stackoverflow for quite some time now. Unfortunately all this without any solutions to be found. So I'm hoping that someone out here might be my savior..
The Situation:
What I am using: PyQt4, Python 2.6, Windows 7
I'm trying to style a QLabel (using a CSS file which I import in my program). The QLabel is in a QListWidgetItem.
So the structure I have is as follows:
QListWidget
+QListWidgetItem
+QLabel
So according to the documentation the way to access the QLabel would be as follows. No problem here.
QListWidget::item QLabel
{
background-color:#000
}
The Problem:
However, I would like the QLabel styling to ONLY change when I hover the QListWidgetItem. Using the following code, the pseudo-state just gets ignored for some reason. The background-color thus gets applied to the QLabels, but it isn't respecting the pseudo state.
QListWidget::item:hover QLabel
{
background-color:#000
}
This situation persists when I run my application stand-alone.
What isn't the solution:
Setting the QLabel pseudo-state to hover won't work because the QListWidgetItem is taller than the QLabel.
Main Question:
Is there a way to change the style properties of the QLabel when, and only when, the QListWidgetItem is hovered and how can this be achieved?
The goal here is to do it ONLY through the css (or qss if you prefer), which is a separate file that gets imported into the program.
Sources:
qss documentation: http://doc.qt.digia.com/4.6/stylesheet-syntax.html
You can't do this at least in Qt 4.7 (did not tested Qt5)
here is good explanation: How to set color of child QLabels while hover parent QFrame with QSS?
it seems that Qt css does not support pseudo-states for descendant elements but original CSS does:
http://codepen.io/anon/pen/olwHs
You should write some code to support such style. Use Enter/LeaveEvent to handle hover and then set style in your code via setStyleSheet()
You may also use dynamic property for that to leave styles in .ui
QLabel[hover="true"] {}
and then set and reset this value in code
Also you may use dynamic property for main widget
[hover="true"] QLabel {}
I have about 40 buttons that are also indicators (On or Off) and once a second I refresh the color of these indicators depending on the state. I do this by changing the stylesheet. Is it over kill to do this and if so should I only set a new stylesheet when it the indicator has changed state or should I use something like QBrush?
Do not dynamically set complete stylesheets. Instead, define an application wide stylesheet using dynamic stylesheet that you parse once at application startup. Then, in the stylesheet, define dynamic stylesheet properties as detailed in the documentation:
There are many situations where we need to present a form that has mandatory fields. To indicate to the user that the field is mandatory, one effective (albeit esthetically dubious) solution is to use yellow as the background color for those fields. It turns out this is very easy to implement using Qt Style Sheets. First, we would use the following application-wide style sheet:
*[mandatoryField="true"] { background-color: yellow }
In your case, you could probably do something like this:
QPushButton[state="on"] {
background-color: green;
}
QPushButton[state="off"] {
background-color: red;
}
Then update the button 'state' property:
pushButton->setProperty("state", "on");
pushButton->setStyle(QApplication::style());
Unfortunately, for Qt 4.6 you will need to force a recomputation of the stylesheet by resetting the style of the widget, hence the setStyle() call.
Using dynamic stylesheets in this way is very fast. I am working on an application that makes heavy use of dynamic stylesheet properties and have not noticed any performance degredation.
Yes. I found that with Qt 4.6.2 on Linux, setting a stylesheet to change the colour of the text on a QLabel is very slow.
The dynamic stylesheet looked like a great solution but for me, the necessary setStyle() was just as expensive as setStyleSheet()!
After much experimentation, I found this alternative to be at least twice as quick, and usually more than 50 times as quick:
QPalette palette = lbl->palette();
palette.setColor(QPalette::WindowText, Qt::gray);
lbl->setPalette(palette);
Depending on how your (static) stylesheet is set up, you'd have to replace QPalette::WindowText with QPalette::Window or QPalette::Button. See the QPalette documentation for details.
In my experience stylesheets consume too much resources, better to avoid them if you can.