I am trying to make a QSlider that has an absolute gradient and a chunked style in the QSlider::add-page part of the slider.
Following Style Sheet code:
QSlider::groove:vertical {
background: #021017;
BORDER-radius: 5px;
position: absolute;
left: 10px;
right: 10px;
}
QSlider::handle:vertical {
height: 10px;
background: #0b1707;
border: 1px solid #46992b;
margin: 0px -10px;
/* expand outside the groove */
border-radius: 5px;
}
QSlider::add-page:vertical {
BORDER-radius: 5px;
border: 1px solid #0e566d;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #46992b, stop: 0.5 #0e566d, stop: 1 #d16a4b);
}
QSlider::sub-page:vertical {
background: #021017;
BORDER-radius: 5px;
border: 1px solid #0e566d;
margin: 0px 1px 0px 1px;
}
QSlider::handle:vertical:hover {
background-color: #46992b;
}
And I get the following output:
But as I move the handle the gradient changes based on the height from the bottom of the slider to the handle. I would like the gradient to be based on the height from the bottom of the slider to the top. Meaning changing the handle position will not change the look of it.
Also is it possible to have a chunked out gradient-- like this progress bar?
For the first question: yes, it is possible. I adjusted the style sheet you provided (uncommented things, you will notice them):
QSlider::groove:vertical {
width: 10px;
/* background: #021017;*/
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #46992b, stop: 0.5 #0e566d, stop: 1 #d16a4b);
border-radius: 5px;
position: absolute;
left: 10px;
right: 10px;
}
QSlider::handle:vertical {
height: 10px;
background: #0b1707;
border: 1px solid #46992b;
margin: 0px -10px;
/* expand outside the groove */
border-radius: 5px;
}
QSlider::add-page:vertical {
border-radius: 5px;
border: 1px solid #0e566d;
/*background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #46992b, stop: 0.5 #0e566d, stop: 1 #d16a4b);*/
}
QSlider::sub-page:vertical {
background: #021017;
border-radius: 5px;
border: 1px solid #0e566d;
margin: 0px 1px 0px 1px;
}
QSlider::handle:vertical:hover {
background-color: #46992b;
}
Summary: style the groove with the gradient and skip the add-page background color.
For the second question, ::chunk is not working, so I think it is not working with the default QSlider. Feel free to implement your own class, which can handle chunks.
Related
I'm using QT widgets.I want to change the style of SliderBar.I can make it like this at the end of my efforts.
I did this
but I need this
I am sharing the stylesheet codes below. How can I do as shown in the second picture.
QSlider::groove:horizontal {
height: 6px;
width: 350px;
background: grey;
margin: 8px;
border: 1px solid #c17d08;
border-radius: 12px;
}
QSlider::sub-page:horizontal {
background: #c17d08;
height: 6px;
border-radius: 12px;
}
QSlider::add-page:horizontal {
background: #e9e9e9;
height: 10px;
border-radius: 12px;
}
QSlider::handle:horizontal {
background: transparent;
width: 22px;
margin: -10px;
border: 1px solid transparent;
border-radius: 5px;
}
I changed your stylesheet to this :
QSlider::groove:horizontal {
height: 6px;
width: 350px;
background: grey;
margin: 8px;
border: 1px solid #c17d08;
border-radius: 12px;
}
QSlider::handle:horizontal {
background: #c17d08;
border: 1px solid #c17d08;
width: 14px;
margin: -5px 0;
border-radius: 6px;
}
QSlider::add-page:horizontal {
height: 10px;
background: #e9e9e9;
border: 1px solid #c17d08;
border-radius: 12px;
}
QSlider::sub-page:horizontal {
background: #c17d08;
height: 6px;
border: 1px solid #c17d08;
border-radius: 12px;
}
your border-radius should be proportional to the length and width to become a circle.
Result :
I am trying to create a gui application to control the volume level of my machine using Qt5 and C++.
This is what I kind of want to achieve.
So, I created the basic layouts and added the QSlider, and then used the following stylesheet to style it:
QSlider::groove:horizontal
{
height: 16px;
background: yellow;
margin: 2px;
}
QSlider::handle:horizontal
{
background: blue;
width: 16px;
height: 16px;
margin: -5px 6px -5px 6px;
border-radius:11px;
border: 3px solid #ffffff;
}
I got the following result:
First the handle is an eclipse, and not a circle. But I wanted to reduce the height of the groove, so I modified the above stylesheet:
QSlider::groove:horizontal
{
height: 10px; // modified here
background: yellow;
margin: 2px;
}
QSlider::handle:horizontal
{
background: blue;
width: 16px;
height: 16px;
margin: -5px 6px -5px 6px;
border-radius:11px;
border: 3px solid #ffffff;
}
And now, the handle of the slider became a rectangle.
Can anyone please answer what's causing it to behave like this, or point me to some docs.
your border-radius should be proportional to the length and width to become a circle.
Try this style :
QSlider::groove:horizontal {
border-radius: 1px;
height: 3px;
margin: 0px;
background-color: rgb(52, 59, 72);
}
QSlider::groove:horizontal:hover {
background-color: rgb(55, 62, 76);
}
QSlider::handle:horizontal {
background-color: rgb(85, 170, 255);
border: none;
height: 40px;
width: 40px;
margin: -20px 0;
border-radius: 20px;
padding: -20px 0px;
}
QSlider::handle:horizontal:hover {
background-color: rgb(155, 180, 255);
}
QSlider::handle:horizontal:pressed {
background-color: rgb(65, 255, 195);
}
And This is for your style (I change margin and padding)
QSlider::groove:horizontal
{
height: 16px;
background: yellow;
margin: 2px;
}
QSlider::handle:horizontal
{
background: blue;
width: 16px;
height: 16px;
margin: -4px 0;
padding: -4px 0px;
border-radius:11px;
border: 3px solid #ffffff;
}
How can i make QTabWidget's corners rounded? Not Tab's, but frame's (?)
I tried:
QTabWidget{
border-radius: 7px;
}
But it isn't working.
QSS for tabs:
QTabBar::tab {
background-color: qlineargradient(x1:0.5, y1:1, x2:0.5, y2:0, stop:0 rgb(253,250,250), stop:0.2 rgb(253,250,250), stop:1 rgb(255,249,234));
border-top-left-radius: 7px;
border-top-right-radius: 7px;
min-width: 8ex;
padding: 5px;
}
QTabBar::tab:selected {
background-color: rgb(253,250,250);
}
QTabBar::tab:!selected {
margin-top: 5px;
background: qlineargradient(x1:0.5, y1:1, x2:0.5, y2:0, stop:0 rgb(253,250,250), stop:0.2 rgb(253,250,250), stop:1 rgb(250,244,229));
color: rgb(93, 109, 109)
}
Just tested this (black color and thick frame just to see something) and should thus work:
QTabWidget::pane {border: 3px solid black; border-radius: 7px;}
I have the following stylesheet:
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,
stop: 0 #2A2A2A, stop: 0.4 #E1E1E1,
stop: 0.5 #E1E1E1, stop: 1.0 #2A2A2A);
background-image: url(:/metal_toolbar);
border-left: 1px solid #9B9B9B;
border-right: 1px solid #9B9B9B;
border-bottom: 1px solid #9B9B9B;
border-top-color: #5A5A5A;
font: bold 12pt;
/*min-width: 20ex;
max-width: 1000ex;*/
padding: 2px;
}
If I don't declare the font in the style sheet, my tabs are sized appropriately for the text they contain, however when I increase the font size, the tab size remains constant and the text gets cut-off. I've tried all the width settings but I want the tab width to scale to what it contains.
Anyone know a work-around or fix for this?
I'm loading the style sheet file into my program as a skin, so I'd prefer stylesheet solutions over programmatic solutions if they exist
EDIT:
Here's the working version with proper tab sizes
QTabBar
{
font: bold 9pt;
}
QTabBar::tab
{
background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,
stop: 0 #2A2A2A, stop: 0.4 #E1E1E1,
stop: 0.5 #E1E1E1, stop: 1.0 #2A2A2A);
background-image: url(:/metal_toolbar);
border-left: 1px solid #9B9B9B;
border-right: 1px solid #9B9B9B;
border-bottom: 1px solid #9B9B9B;
border-top-color: #5A5A5A;
min-width: 20ex;
padding: 2px;
}
Set the font from the QTabBar then. Rough pseudocode below.
font = tabbar.font()
font.setPointSize(12)
font.setBold(true)
tabbar.setFont(font)
You should be able to access the QTabBar from the QTabWidget, and just set your style sheet without the font. I hope this can help.
According to CSS Tricks, the following CSS syntax would result in left border gradient.
.left-to-right {
border-width:3px 0 3px 3px;
-webkit-border-image:
-webkit-gradient(linear, 100% 0, 0 0, from(black), to(rgba(0, 0, 0, 0))) 1 100%;
-webkit-border-image:
-webkit-linear-gradient(right, black, rgba(0, 0, 0, 0)) 1 100%;
-o-border-image:
-o-linear-gradient(right, black, rgba(0, 0, 0, 0)) 1 100%;
-moz-border-image:
-moz-linear-gradient(right, black, rgba(0, 0, 0, 0)) 1 100%;
}
I'm trying to get the border gradient on the bottom of the element.
I tried changing this
border-width:3px 0 3px 3px;
to this
border-width:0 0 3px 0;
this
border-width:0 3px 3px 3px;
And it doesn't work, can anybody help me with getting that bottom border to work?
You may need a WebKit browser to do this.
Here would be a fiddle for one to work with; http://jsfiddle.net/HsTcf/
Thanks.
border-width: 0 0 3px 0;
is correct.
However, the following changed needed to be made:
... -gradient(right, ...
needed to be changed to
... -gradient(top, ...
and 1 100%; to 100% 1;.
Demo: jsfiddle.net/HsTcf/3
Here is another way that works for bottom borders. This is the complete class declaration from a site example.
#header_bg {
position: fixed;
top: 0px;
width: 100%;
height: 121px;
top: 0px;
background-color: #fff;
box-shadow: 0 0 7px rgba(0, 0, 0, 0.1) !important;
z-index: 10;
}
<div id="header_bg"></div>
I am assuming above you are trying to make a fixed header. The most important part of course is the box-shadow property. This will work in most modern browsers as well.