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);
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 would like to change the colors of a QTableWidget. I am almost getting the result I like, but two areas in the vertical header remain white:
Before writing this post I actually managed to color also the upper left corner, but not the other area. Here is the stylesheet I am using:
QTableCornerButton::section {
background-color: #8b8d8e;
}
QHeaderView::section {
color: white;
background-color: #747678;
gridline-color: #747678;
}
Finally found the answer myself:
/*The top-left area is actually a button:*/
QTableCornerButton::section {
background-color: #8b8d8e;
}
/*The lower part of the vertical header:*/
QHeaderView {
background-color: #8b8d8e;
}
The original css I posted (QHeaderView::section) referred only to the header entries, not the header itself.
I'm creating an image grid in Qt as seen in these screenshots:
One row
Row break
The problem occurs while resizing the window. The last image breaks onto the next row before it touches the edge of the window. This is even more noticeable when the items are larger. Is it possible to change some padding/marging/spacing to allow the grid to bump into the edge, then break to the next row?
I've tried using this, but it doesn't work:
#listWidget{
background-color: green;
padding-top: 5px;
}
#listWidget::item{
background-color: red;
margin: 0px;
padding: 0;
}
As a side question, I am able to remove the item padding, as seen with the red background, by using this stylesheet:
#listWidget::item{
padding: -1px -3px -4px -4px;
}
Is there a better way to remove the padding from individual items so they are right next to each other? Why doesn't margin: 0; padding: 0; work?
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