Stylesheet on QScrollBar leaves background of scrollbar with checkerboard pattern? - c++

When I style my QScrollBar using a stylesheet, the background color is checkered instead of being solid.
QScrollBar:horizontal {
background-color: grey;
}
How do you make the background of the scrollbar a solid color?

What you are referring to as "the background" is actually the two sub-elements add-page and sub-page. You need to define the background element on those sub-elements.
The simplest solution would be to remove the background on both. Then it would inherit the background color grey that you have already set on QScrollBar:
QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {
background: none;
}
But if desired, you could style each individually to your liking:
QScrollBar::sub-page:horizontal {
background: red;
}
QScrollBar::add-page:horizontal {
background: green;
}
Source.
Unfortunately, this solution is rather hard to divine from the official documentation.

Related

Qt QTabWidget background color

I have been trying to set the background color of a QTabWidget to black (or any other color for), but have been unsuccessful in doing so.
It seems that you need the option autoFillBackground set and then also set "background-color: black;" in the stylesheet. This then displays it properly in the Designer, but fails in the application.
This answer suggests to enclose it in another QWidget and then use the transparency, but that is a hack around the issue.
How do I set the background color of a QTabWidget via stylesheets?
EDIT
Setting QTabBar { background-color: black; } results in the following image.
As an alternative to QTreeWidget, use QTabBar + QStackedWidget and the following stylesheet
QTabBar { background-color: black; }
or use
Qt: Styling QTabWidget

How to set only QTabWidget background color stylesheet

I have a Qt application that, among many other widget types, uses a QTabWidget. I'm having difficulty styling the background color for this object.
I've tried some of the following lines, which I found from other forum posts, in my stylesheet with no effect on the program
QTabWidget { background-color: black; }
QTabWidget::pane { background-color: black; }
QTabWidget#tabWidget { background-color: black; }
QTabWidget#tabWidget::pane { background-color: black; }
If I use QWidget { background-color: black; }, then yes my color is properly changed, but then all of the other widgets in my program are changed as well... so this isn't what I'm looking for...
I've also tried it in code with ui->tabWidget->setStyleSheet("background-color: black"); But this too is undesirable because it changes the background color of all of its children widgets.
Does anyone have any other ideas on how to style a QTabWidgets contents background area?
About a year late but I recently ran into the same problem and got it working.
First of all QTabWidget has a child QWidget for every tab you make. That is the area that you put your other widgets into, and that is what you want to set the background color of.
Set the style-sheet by doing this.
1)Determine the name of your tab widgets from the design object window top right, they should match the currentTabName that you set when creating your tab.
2)Realize this is a QWidget not a QTabWidget this is why QTabWidget { background-color: black; } does not work.
3)Realize that by specifying the object in the style-sheet with the '#' the child object will not inherit the style-sheet.
For me I specified my style-sheet as such, repeating for each tab object name that I had:
#objectName {background-color: rgb(240,240,240);}
This provided me with the exact behavior I needed. In my case I wanted to get the natural gray background onto my Tab pages but not override the child components on the tab pages.
I hope this helps someone in the future...

Remove blue focus border around QGraphicsView

In Qt (for a Maya plugin), I have a QSplitter containing 2 QGraphicsViews.
One of these QGraphicsViews contains some QLineEdits.Whenever I click on one of these QLineEdits, it gets a blue border (focus), but the QGraphicsView gets a blue border too. How to avoid the QGraphicsView to get a blue border ?
You can try setting style sheet eg:
QGraphicsView:focus {
border: none;
outline: none;
}

Qt TableView: How to get rid of the extended grey rectangle from the row headers

How do I get rid of grey area as seen in the image below. It seems like if the table does not fill the entire space, the grey color just extends until the end.
I coded something similar to this image in C++.
It's not just grey color, it's a vertical header. As I see it, your options are:
Get rid of the header in Designer and create your own column with numbers, not editable, of course
Use custom stylesheet for QHeaderView, like (example, don't know your preffered colors)
QHeaderView::section
{
background-color: transparent;
color: black;
font: 10pt "MS Shell Dlg 2";
}
It works with QTableView.
UPD: Try the following: set the stylesheet for QHeaderView AND it's sections if needed, like
QHeaderView
{
background-color: white;
}
This will paint your header white, no grey, like you wanted. Then you can improve the stylesheet, styling sections (probably, you'll like proper borders and all, so don't use "border: 1px solid balck", play with border-top and/or border-bottom, otherwise sections will get ugly double inner borders).
After that you can consider styling only one header or both, further improve styleshhet, but the point remains that QHeaderView and it's sections can be styled independently

Qt stylesheet of dock area splitter

How to change the style sheet of splitter/handle beside QDockWidget when it is added to DockWidgetArea. There is one main movable handle and multiple handles between each dockwidgets on that side. I would like to change at least bg colour and border of the handle and hover colour.
It would help if I know what kind of object it is or to get some pointer to the handle to setStyleSheet on it.
Ok I found it after some digging inside source code. Finally the answer was so simple and was screaming from the documentation of style sheet:
Note: Use QMainWindow::separator to style the resize handle.
Ok so the code is simple:
QMainWindow::separator
{
background-color: green;
width: 4px;
border: none;
}