I'm having an issue generating the correct code with the #if statement based on a variable.
SASS
=band($name, $color)
.band-#{$name}
background-color: #{$color}
#if $name == white
font-size: 100px
#else
font-size: 20px
+band('white', $white)
+band('black', $black)
to generate
.band-white{background-color:white; font-size:100px;}
.band-black{background-color:black; font-size:50px;}
The issue is that your mixin is comparing the variable that is coming in with a color.
You are passing in the string 'white' which is not the same as the HTML color white.
Have a look at the SassScript DataTypes.
So, to fix your Sass, you will have to either change your code to
=band($name, $color)
.band-#{$name}
background-color: #{$color}
#if $name == 'white'
font-size: 100px
#else
font-size: 20px
+band('white', $white)
+band('black', $black)
or
=band($name, $color)
.band-#{$name}
background-color: #{$color}
#if $name == white
font-size: 100px
#else
font-size: 20px
+band(white, $white)
+band(black, $black)
The latter will not give you anything useful if you pass in anything else than a color as the first argument.
By the way, you could also simplify the condition by using a single-line if in case you are using Sass 3.3 or higher:
font-size: if($name == white, 100px, 20px)
I suspect it's a white space issue. Do you get anything useful in the logs?
I was able to get a version of your code working:
#mixin band($name)
background-color: $name
#if $name == white
font-size: 50px
#else
font-size: 20px
.band-white
#include band($name: white)
.band-black
#include band($name: black)
And you can see it working here https://codepen.io/sitrobotsit/pen/aWQxNE
Related
I'm trying to make a progress bar that can dynamically change part of it's color depending on a slider's value. The closest I can get to that right now is by using:
bar->setStyleSheet(QString("QProgressBar::chunk:vertical {background: qlineargradient(x1:0, y1:0, x2: 0, y2: 1, stop:0 red, stop:0.5 green); border-radius: 9px;}")
+QString("QProgressBar::vertical {border: 1px solid #b4adad; border-radius: 9px; background: #2f2828; padding: 0px; text-align: left; margin-right: 4ex;}"));
I have tried setting the second stop point to slider->value() which takes away the whole style sheet leaving me with a blank progress bar.
I have tried just using CSS code which also takes away the style sheet:
{background: linear-gradient(to bottom, white 0%, blue 25%, blue 100%); border-radius: 9px;}"
I'm confused because I can use CSS to set the background but I can't get it to work unless I use qlineargradient, why is this? What needs to be done in order to implement CSS in a Qt stylesheet without restriction?
Is it possible to set the value of a stop point to the changing value of a slider?
I also attempted using the setStyleSheet function within an if statement so that the stylesheet itself will change depending on the value of the progress bar:
if (bar->value()<slider->value()) {
however this doesn't dynamically change the stylesheet. It seems as though it runs the if statement one time prior to opening the app. Does QT run a while loop that runs through the code continuously while the app is open or am I mistaken?
From https://doc.qt.io/qt-5/qprogressbar.html#valueChanged, there is a signal void QProgressBar::valueChanged(int value) that you can connect to a slot and make the change you want for the QProgressBar sylesheet, for example :
void MainWindow::on_progressBar_valueChanged(int value)
{
if (value >= 0 && value < 50)
ui->progressBar->setStyleSheet("border: 2px solid grey; border-radius: 5px; text-align: center;");
else if (value >= 50 && value < 75)
ui->progressBar->setStyleSheet("background-color: #05B8CC; width: 20px;");
// and so on ...
}
I want to change the background color of the header when I use the QWidget. I tried the following methods but they didn't work:
QTreeWidgetItem * header = ui->treeWidget->headerItem();
header->setBackground(0, QBrush(QColor(185,192,201)));
header->setBackgroundColor(0, QColor(185,192,201));
setStyleSheet("QHeaderView::section { background-color:red }");
I also want to know how to hide the header's dividing line?
I've found a method to change the header's style,but I don't know why my previous method did not work.
QHeaderView::section {
color: black;
padding: 2px;
height:20px;
border: 0px solid #567dbc;
border-left:0px;
border-right:0px;
background: #f9f9f9;
}
Why don't you use only the stylesheet?
YourQTreeWidget QHeaderView::section {
background-color: red; // for the bakcground
border-right: none; // right-border of each section
border-left: none; // left border of each section
}
As you can read here (and as you see in your example) setBackgroundColor does not work for header item (I suspect that this is due to difference between header and row items).
You should to reimplement QHeaderView or to try option described above.
I want to change the background of a QGroupBox, however I would like to only change the inside background (the darker shade of gray below each QGroupBox's title) as shown here:
What I currently have is
QGroupBox {
background-color: red;
border: 3px dashed black;
}
which changes the background of the entire QGroupBox like this:
Is there a way in Qt to only change the "interior box" background rather than the whole container? Thank you in advance.
I guess there are 2 QGroupBox'es involved here, since that is not really clear from your post. Or is there a group box and some other inner container widget?
In either case you should be able to use stylesheets like following:
QGroupBox {
background-color: red;
margin-top:1em;
}
QGroupBox QGroupBox {
background-color: green;
}
QGroupBox::title {
subcontrol-origin: padding;
subcontrol-position: left top;
background: transparent;
margin-top: -2.5em;
}
This will give you following result:
You can of course replace the inner group box by an arbitrary widget.
You can do it using "setStyleSheet" function of widgets.
Get the inner group box object. And set the background color using "setStyleSheet" function.
Pseudo Code:
QGroupBox *innerGBox = new QGroupBox();
innerGBox->setStyleSheet("background-color: red");
To know more about setting styles programmatic , refer below link.
http://doc.qt.io/qt-4.8/stylesheet-examples.html
You need to tell Qt a little more about the kind of style you want, specifically the margins. Playing around a little with this code should give you the desired results:
QGroupBox {
background-color: red;
border: 3px dashed black;
margin-top: 1ex; /* leave space at the top for the title */
}
QGroupBox::title {
subcontrol-origin: margin;
padding: 0 3px;
}
Take a look at the Stylesheet examples
Here's I am trying to do that:
but I set that stylesheet in my QTableView:
QTableView {
gridline-color: black;
background-color: transparent;
}
QHeaderView {background-color: transparent;
}
QHeaderView::section{
border-style: none;
border-bottom: 1px solid rgb(0,0,0);
background-color: transparent;
margin-bottom:5px;
margin-top:5px;
}
QTableView QTableCornerButton::section {
bottom-style:none;
border-bottom: 1px solid rgb(0,0,0);
}
Result is this:
I can handle with size problem for future but there is two main problem over here:
1.Column text between border there isnt any space, I did margin-top:5px; and margin-bottom:5px; but it changed for all QHeaderView not only QHeaderView's Text. (Solution is use padding instead of margin)
2.Every row has a right ,left even top border. I dont want that.
I tried this:
QTableView QTableCornerButton::section {
border-style:none;
border-bottom: 1px solid rgb(0,0,0);
}
Unfortunately there is a problem at QTableCornerButton:section it doesn't work...
Thank you for any helping
Note : I haven't verified, these are just suggestions to try, please upload the output if needed
1 - What do you mean by "it changed for all QHeaderView not only QHeaderView's Text"?
Maybe you expected to set margin only to the headerview's content (text) : in that case use the padding not margin.
QHeaderView::section{
/* your style */
padding-bottom:5px;
padding-top:5px;
}
2 - Every row has a right ,left even top border. I dont want that.
QTableView {
/* sone additional style */
gridline-color: cyan
background-color: cyan
}
QTableView::item
{
border-style: none;
border-bottom: 1px solid rgb(0,0,0);
}
I would try to use the border-style (set to none) as you did in QHeaderView's style.
Edit : You certainly must disable the showgrid's option of your QTableView by code to make it a working solution
tableView.setShowGrid(false);
I'm using this template. I don't want the left & right hand columns available, I need to use the whole space for the main column. I've disabled every module in the left & right columns, the content is correct on the left side starting under pic1 but on the right side I've got this big space on the right side. I've changed all my rightcolumn settings in template.css to width: 0px but still no luck. Does anyone have any other suggestions for me please?
just a first quick guess:
In the index of your template, line 43-44
<?php if($this->countModules('left') xor $this->countModules('right')) $maincol_sufix = '_middle';
elseif(!$this->countModules('left') and !$this->countModules('right'))$maincol_sufix = '_big';
else $maincol_sufix = ''; ?>
here the template detects which modules are active and seems to change the class suffix. Here you need to inject your own. Let me know if you need more help...
EDIT:
Your template uses the following style classes to change the mainbody:
#maincolumn {
float: left;
margin: 0 5px;
overflow: hidden;
padding: 0;
width: 530px;
}
#maincolumn_middle {
float: left;
margin: 0 5px;
overflow: hidden;
padding: 0;
width: 740px;
}
#maincolumn_big {
float: left;
margin: 0 5px;
overflow: hidden;
padding: 0;
width: 967px;
}
The last one should be injected if no left and no right modules are found. You may change the width of this one to see a effect.
In addition to setting the rightcolumn width to 0px, you also need to expand the #maincolumn. since you only want the one column, I would recommend changing width:530px; to width:100%; or something similar. You can also remove the float:left; rule