Problem in stylesheet of Qt APP - c++

In my app, i have a section that is top widget, the color of the top widget is gray, and i've been put severl widget on top widget, like QComboBox, QLineEdit and 2 QButton, but i have a problem when i right click on QLineEdit as you seen in below picture, the color of default context of window is gray, or when i open the QComboBox the color of background is gray. I'll set the background color of two these widget to white but doesn't work. So, how can i fix this?
Sample for better understand:
http://0000.4.img98.net/out.php/i52512_problem.png
Please help me

The style sheet propagates to all the child widgets, so you have to limit their range by using the right selectors. Since the context menu is a child of the QLineEdit it is also affected.
// What you have probably done:
myLineEdit->setStyleSheet("background-color: gray");
// What you should have done:
myLineEdit->setStyleSheet("QLineEdit { background-color: gray }");
// What you should do if there might be child widgets of the same type
// but for which you don't want the style to apply:
myLineEdit->setObjectName("myLineEdit");
myLineEdit->setStyleSheet("QLineEdit#myLineEdit { background-color: gray }");
See "The Style Sheet Syntax - Selector Types" for details.

Related

Making Qwidget Transparent on VideoWidget

I have a QWidget which should take place over the central widget of my application which is a VideoWidget for playing video. The problem is that I can't set background of the QWidget to be transparent.
Use a StyleSheet (you can do that in code with setStylesheet or in the ui file : RMB on the widget you want "Change stylesheet" or even in the properties tab)
for instance
"background-color: rgba(255, 255, 0, 50);"
gives a yellow transparant look:(example of a button used on top of another button)
With stylesheets you can control the look of a complete program or just the specific widgets you want. More info in the style sheet reference
You could make the full Widget invisible:
QWidget::setHidden(true);

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...

Styling QListWidget item widgets: selected state

I have a window which displays tiles, each tile having some set of information. Tiles are arranged in a tabular structure. The way in which this is implemented is, a QListWidget is used to hold tiles and each tile is set as the item widget in QListWidgetItems in QListWidget.
I have styled the tiles using a stylesheet. My problem is, I cannot get a tile highlighted in some way when the tile is selected. If I do not use stylesheets at all, default selected highlighting works. But as soon as I apply styles to tiles, there is no difference in the tile in non selected and selected states.
I tried to do it in following way but it does not work.
.tile
{
/*non selected style*/
}
.tileList::item:selected
.tile
{
/*selected style*/
}
Any idea how I can achieve this?
I solved it in Qt Designer by setting the palette how I wanted it and then put
QListView::item:selected { background: palette(Highlight) }
as the styleSheet. Maybe this helps somebody.
If you want to do it from a central qss, I guess you'll have to remove the ".tile" part from the code in the question.
.tileList::item:selected
.tile <--- remove this line
{
/*selected style*/
}
I could get this done to some extent (not a comprehensive solution), by doing following.
Make tile widget semi transparent.
Set a background color to QListWidgetItem
Set a different background color to QListWidgetItem when selected
Styles:
.titleList::item {
background-color: #fff;
}
.lstSnapQuote::item:selected {
background-color: #5555FF;
}

QTextEdit background color change also the color of scrollbar

I want the QtextEdit in my app to be green so I set the stylesheet to
background-color: rgb(109, 255, 99);
However this also change the background color of the scrollbars and even when I click mouse right button in the textedit the menu that is shown is also green and that is not what I expected.
I'm using Qt Designer to design gui and then I used the uic to generate c++ file.
in the c++ file it looks like this:
textEdit->setAutoFillBackground(false);
textEdit->setStyleSheet(QString::fromUtf8("background-color: rgb(109, 255, 99);"));
textEdit->setReadOnly(true);
Anybody know how to set the background color only for the area where text would be?
Thanks
All child objects of your text edit inherit the stylesheet, so all children (e.g. context menus) will have a green background.
You should select your QTextEdit only in your stylesheet, i.e.
textEdit->setStyleSheet("QTextEdit { background-color: rgb(109, 255, 99) }");
Note that you can set the stylesheet at application level, too, so that all QTextEdit's in your app will have your specified background:
qApp->setStyleSheet("QTextEdit { background-color: rgb(109, 255, 99) }");