QSS stylesheet for QtWizard - qt

I'm very new to Qt.
I built an app that has many widgets that combine QLabel and QLineEdit, something like:
someRadioButtons label lineEdit
Multiple instances of these are put in several QWizardPages which process the lineEdits. Everything works fine. I am having an issue styling the GUI.
I checked some QSS repositories and got the base idea that if you define stylesheet in separate file that has css-like definitions for different widgets, you can very simply apply it to your app. Mine looks something like this:
QMainWindow
{
background:#000000;
}
QFrame
{
font: bold;
font-size:12pt;
background-color: #f25050;
border-radius: 10px;
margin: 2ex;
}
QLabel
{
padding-left:2px;
font-weight:bold;
font-size:12pt;
color:#000000;
background:#f25050;
}
QGroupBox
{
background: #f25050;
font: bold;
font-size: 12pt;
border: 1px solid #ffffff;
border-radius: 10px;
margin-top: 2ex;
}
So background is black. All widgets are placed in groupboxes that has reddish color.
Issue is the following:
I need QLabel defined as I want labels in whole app to be bold and transparent.
When QLabel is defined, QFrame setting loses meaning, because all text in it becomes transperent - really big issue with QWizard pages where I was setting title and subtitle.
So what should I do?
I can mimic title/subtitle in QWizardPages by creating some groupbox with some text in it, but that seems too much extra work for something so simple - I wish title and subtitle in QWizardPage to be styled differently than QLabel, I don't even need QFrame styling.
I could set label fonts when making the custom widget, but not sure how that will affect the GUI, as so far I realized that stylesheets set for something, apply to everything that is displayed, not one particular "something".
Can someone explain me how to particularly style different elements in some widget/layout? I saw some QWidget#some_custom_name qss definitions, but again, how would you apply that to particular element and not all similar elements on a page?
Is there some way to affect qss of titles and subtitles in widgets, particularly QWizardPage? I tried making a style for QWizardPage and QWizardPage::title, with no luck, as QLabel setting made all text labels transperent.

Related

Jodit: when launching editor text in editor is centered and background color selection disappears

I am adding jodit editor to a page of a site I run, but when I do so the cursor (inside the editor) is centered and when you start typing it also is centered.
I tried adding a CSS defintion .editor { text-align: left; } but that doesn't change things.
Less important secondary question: before adding the editor I had a background color defined for the textarea which disappears when I add the editor. How do I select a bg color for the editor? I tried doing so on the homepage of Jodit (https://xdsoft.net/jodit/play.html?currentTab=Themes) but even when I change it there it does not change for me (at least not in Chrome)
You can use
.jodit-container {
text-align: left;
}
or text-align: initial;
You probably have some global css text-align: center which is also applied to the editor. I don't know if you applied the editor class to the editor yourself, but the default doesn't have that class.

Unbounce Stylesheets not working

I'm working on an Unbounce project and I can't get the stylesheets to work.
I wanted to change the font-size of the labels of an option on the form. I saw (using inspect element) that the following CSS created affects the size: #lp-pom-form-55 .lp-pom-form-field .option label
So I created a stylesheet in Unbounce like this:
<style>
#lp-pom-form-55 .lp-pom-form-field .option label {
font-size: 16px !important;
}
</style>
And it just doesn't work. I also tried it without the style tag like this:
#lp-pom-form-55 .lp-pom-form-field .option label {
font-size: 16px !important;
}
It still didn't work. I even tried basic things like setting the background color of normal text field id's to black !important with no solution.
What is the correct way to apply styles to Unbounce pages?
I've realized that the code within the <style> tags is the correct way to do it. The problem was that the custom CSS doesn't display in the designer view, it only shows on the live page.

How to style Polymer dropdown menu arrow

New to Polymer, and the docs seem a little 'light' on examples. I'm trying to style a dropdown menu so everything is white on a blueish background. Most things (tabs, toast, etc.) are working, but the dropdown-menu stubbornly refuses to show the little 'arrow' button in anything other than murky grey.
Example JSBin
The styling code is:
<style>
:host {
display: block;
/* Main vars */
--ki-teal: #4790A8;
--paper-tabs-selection-bar-color: #fff;
--paper-tab-ink: #fff;
/* Toolbar colours */
paper-toolbar.ki {
--paper-toolbar-background: var(--ki-teal);
}
/* Project select dropmenu colours */
paper-dropdown-menu-light.ki {
--paper-dropdown-menu-color: #fff;
--paper-dropdown-menu-focus-color: #fff;
--paper-dropdown-menu-button: {
color: #fff;
}
--paper-input-container-color: var(--ki-teal);
--paper-input-container-focus-color: #fff;
--paper-dropdown-menu-input: {
border-bottom: none;
};
}
/* Notifications */
#toastSave {
--paper-toast-background-color: var(--ki-teal);
--paper-toast-color: white;
}
}
</style>
But the --paper-dropdown-menu-button doesn't seem to have any effect, or I'm not using it right. Any guidance appreciated.
In addition, you'll see (at least on Chrome/Windows) that the underline bar when the dropdown has focus is not aligned properly with the active tab bar. I guess that's just a Polymer CSS glitch which will get worked out eventually, unless it's something I need to take care of in the <style> section as well?
Use --iron-icon-fill-color in your paper-dropdown-menu class if you want have other iron-icons also which you don't want to style, else you can style use it in host if you want.
Another way of doing it will be giving color to mixin --paper-dropdown-menu-icon. As per paper-dropdown-menu documentation it is
A mixin that is applied to the internal icon
Lastly, if you look at the code of paper-dropdown-menu-light you'll notice that icons have default value as --disabled-text-color. So, if you change this value that should do the trick for you. I'll recommend not to use this method as this is a default variable for material design theme and Polymer has used this as default value at lot of places. So, unless to know what you are doing avoid this method.
In Polymer if an element is using some other element internally you can always refer the style guide of internal element and use it directly. Like here we are using iron-icons styles to style the icon which is inside paper-dropdown-menu
I don't think Polymer has directly mentioned this in their styling guide but you can find this detail written at the end of styling details of paper-dropdown-menu and generalise it
You can also use any of the paper-input-container and paper-menu-button style mixins and custom properties to style the internal input and menu button respectively.

QT Stylesheet for HLine/VLine color

I'm pretty new to this Qt thing and its whole stylesheet system. My background of HTML/CSS helps a little to understand the system, but a lot of things just happens for no apparent reason....or don't happen.
Anyway, the mystery of the HLINE and the VLINE and how to change the lines' color is just a mystery for me. I learned from other questions and various fora that it's linked to the QFrame elements. And I can change the color of the line if I just use something like
QFrame
{
color: red;
}
But this of course changes the color of tons of other things that uses a QFrame as well. I could of course go into the HLINE element and put color: red; in there and that works fine, but my app requires that I put everything in a single stylesheet that gets loaded into the app. So styling individual elements is not an option.
A solution would look something like
QFrame HLine, QFrame VLine
{
color: red;
}
QFrame[frameShape="4"] /* QFrame::HLine == 0x0004 */
{
color: red;
}
QFrame[frameShape="5"] /* QFrame::VLine == 0x0005 */
{
color: green;
}
HLine and VLine are tricky to style. It's worth taking a look at the "Detailed Description" section of the documentation. For a quick fix, I found that this set of rules allows customizing the appearance of such lines via stylesheet in a reliable and relatively clean manner:
QFrame[frameShape="4"],
QFrame[frameShape="5"]
{
border: none;
background: red;
}
This works regardless of the frameShadow property, which otherwise affects their appearance and the effect of style rules. Keep in mind that the width of the lines are not 1px by default -- this can be changed using the min-width, max-width, min-height or max-height properties, as appropriate.
For a more detailed overview of my findings, read along.
Most QFrames have the QFrame::Plain frameShape by default, but HLine and VLine's default frameShape is QFrame::Sunken. This means that they are not really lines, but thin boxes that contain a mid-line that's used to provide the 3D effect. From the documentation:
The mid-line width specifies the width of an extra line in the middle of the frame, which uses a third color to obtain a special 3D effect. Notice that a mid-line is only drawn for Box, HLine and VLine frames that are raised or sunken.
If you set the frameShape to Plain, this midline is still visible, and can be styled with the color property (note: that's not a background-color or border-color!)
But this doesn't work for a HLine/VLine that's left with the default Sunken appearance. One way to fix this could be to set separate styles for Plain and Sunken QFrames by using attribute selectors with the decimal values of the property enums (which are described in the documentation in hehadecimal), like so:
/* Reference (from doc.qt.io/qt-5/qframe.html#types):
* - frameShape[4] --> QFrame::HLine = 0x0004
* - frameShape[5] --> QFrame::VLine = 0x0005
* - frameShadow[16] --> QFrame::Plain = 0x0010 (default for most widgets)
* - frameShadow[48] --> QFrame::Sunken = 0x0030 (default for HLine/VLine)
*/
QFrame[frameShape="4"][frameShadow="16"],
QFrame[frameShape="5"][frameShadow="16"]
{
...
}
QFrame[frameShape="4"][frameShadow="48"],
QFrame[frameShape="5"][frameShadow="48"]
{
...
}
but since the styles that work for HLine/VLine with QFrame::Sunken also work for those with QFrame::Plain, it's usually a waste to do so. I show them above for educational value only about how to use attribute selectors.
The best approach is to treat the QFrame as the box that it is, and either (1) set border-top or border-right coupled with a max-height: 0px (or max-width for a VLine), to ensure the inside of the box doesn't take up space in the layout; or (2) use a background color coupled with border: none (in which case, max-height/width should be 1 or larger, otherwise the QFrame is invisible). The latter is the solution I'd recommend, as shown in the first code block above.
Hope this helps!
According to QDarkStyleSheet issue, You could use:
QFrame[width="3"], QFrame[height="3]
These selectors, they seem to work cross-platform, and they are unlikely to change.
Probably better than using enum values as ints, as they are likely to change with Qt versions, and line styling are not, as they fulfill certain requirements.
but my app requires that i put everything in a single stylesheet that
gets loaded into the app.
You can use Conflict Resolution. Suppose that you have a QMainWindow object with lots of widgets on it . Set these style sheets for the maindionw style sheet :
QLabel#label{
background-color: rgb(255, 170, 255);
}
QPushButton#pushButton{
color: rgb(0, 0, 255);
}
QFrame#line{
background-color: rgb(0, 170, 255);
}
The first css just changes a QLabel name label on your mainwindow and set its back color to rgb(255, 170, 255). The next will change text color of a QPushButton named pushButton to (0,0,255);. The third one change property of a line.Lines are just a QFrame.
So the solution that I can offer is to place your css in a file and then load this file using QFile and QTextStream and then set the contents of the file for css of your main winodw or main widget using setStyleSheet ( const QString & styleSheet ) function. or If you are using creator just right click on your main window and select change stylesheet and then paste your css. But bear in mind that you should use conflict resolution.
You can leave Qt's hlines and build up your own very easy. For frames you want looks like hline add property "class" as "HLine" (for example), in designer or in c++ code:
frame->setProperty("class", "HLine")
.
Then, you can define in main view's or in global app stylesheet something like this:
QFrame.HLine {
border: none;
border-bottom: 2px solid red;
}
and you will get horizontal two pixels red line.

How do I customise the appearance of links in QLabels using style sheets?

I have a QLabel with a Qt stylesheet that sets a dark background:
QLabel {
background: black;
color: white;
}
This works fine until I add text with an embedded URL and set the Qt::TextFormat to Qt::RichText. The link displays as the default dark blue, which is hard to read on a dark background.
I've tried customising it via a stylesheet such as:
a { color: white; }
QLabel!visited { color: white; }
but this doesn't have any effect. The one thing that does seem to work is changing the application's QPalette:
QPalette newPal(qApp->palette());
newPal.setColor(QPalette::Link, Qt::white);
newPal.setColor(QPalette::LinkVisited, Qt::white);
qApp->setPalette(newPal);
However this requires the colour to be hardcoded. Is there any way I can set the colour from a stylesheet instead?
EDIT:
I've discovered a further problem with customising the palette. If I want to just modify the palette of my widget (substituting widget for qApp in the sample above) then this doesn't work. I don't want to affect all the other QLabels in the app, so how do I limit the palette changes to this widget?
One way is to add style="color: whatever" or a class to the inner <span> of the link. I haven't figured out yet how to apply this to the whole application but it's a good start.
I've had little success explicitly setting the QPalette -- it works if you set it for the entire application, but not if you set it in the widget. In the end though, the easiest thing for what I needed to do was use a QTextBrowser instead which supports a subset of HTML. I could then override the colour of links using a regular CSS stylesheet:
QTextBrowser browser;
// IMPORTANT! - set the stylesheet before the content
browser->document()->setDefaultStyleSheet("a {color: white; }");
browser->setText(html);
Short answer is no. Recently I had to do this.
QLabel!visited doesn't work because Qt doesn't track whether QLabel were visited or not.
QLabel { color: ... } doesn't work for links. Can't find why but all I found is a suggestion to use QPallete in this case.
You can set the color tag in the HTML to
{ color: inherit; }

Resources