How to style widgets inside a scrollArea?
-
I have a widget with scrollArea in it and other widgets which are inside the scrollArea.My problem is the qss i am using to style the widgets inside the scrollArea, is not applying.
/qss********/
MyWidget
{
background-color: white;
}QLabel
{
border: none;
background-color: white;
font-size: 10pt;
}QPushButton
{
border-style: none;
color: white;
font-size: 12pt;
}QPushButton:pressed
{
border-style: none;
color: black;
}QLineEdit
{
color: black;
font-size: 14pt;
}QComboBox
{
border-style: solid;
border-width: 2px;
border-radius: 3px;
font-size: 14pt;
min-height: 38px;
}QComboBox:!editable, QComboBox::drop-down:editable
{
background: white;
border-style: solid;
border-width: 2px;
border-radius: 3px;
}QComboBox::drop-down
{
subcontrol-origin: padding;
width: 25px;border-left-width: 1px; border-left-style: solid; border-top-right-radius: 3px; border-bottom-right-radius: 3px;
}
QComboBox QAbstractItemView
{
border: 2px solid lightgray;
selection-background-color: lightgray;
}QComboBox QAbstractItemView::item
{
min-height: 80px;
}
QScrollArea#scrollArea
{
background: white;
border-style: none;
}QWidget#scrollAreaWidgetContents
{
background: white;
border-style: none;
} -
Hi and welcome to devnet,
Please show the code you use to setup your QScrollArea, the widgets in it and the style sheet.
-
@SGaist This is how i am setting up qscrollarea.
I have used qt designer to create the widget.
The QSS is applying to widgets outside the scrollarea, but not to widgets inside scrollarea.//Set up Scroll Area
ui->scrollArea->verticalScrollBar()->setVisible(false);
ui->scrollArea->horizontalScrollBar()->setVisible(false);
ui->scrollArea->horizontalScrollBar()->setEnabled(false);
ui->scrollArea->setWidgetResizable(false);
ui->scrollAreaWidgetContents->setGeometry(0,0,ui->scroll_Area->width(),1000);
this->setStyleSheet(fetchQss(staticMetaObject.className()));Below is the QSS used to style the widgets inside and outside scrollArea.
CustomWidget
{
background-color: white;
}QCheckBox::indicator
{
border: none;
width: 101px;
height: 51px;
}QComboBox
{
border-style: solid;
border-width: 2px;
border-color: #99B359;
border-radius: 3px;
font-size: 14pt;
min-height: 40px;
}QComboBox:!editable, QComboBox::drop-down:editable
{
background: white;
border-style: solid;
border-width: 2px;
border-color: #99B359;
border-radius: 3px;
}QComboBox::drop-down
{
subcontrol-origin: padding;
subcontrol-position: top right;
width: 25px;border-left-width: 1px; border-left-color: #99B359; border-left-style: solid; border-top-right-radius: 3px; border-bottom-right-radius: 3px;
}
QComboBox::down-arrow
{
image: url(:/drop.png);
}QComboBox QAbstractItemView
{
border: 2px solid white;
selection-background-color: white;
font-size: 14pt;
}QComboBox QAbstractItemView::item
{
min-height: 70px;
}QScrollBar:vertical
{
width: 25px;
}
QScrollBar::handle:vertical
{
background: #E3E3E3; min-height: 25px;
}QPushButton
{
border-style: none;
color: white;
font-size: 14pt;}
QPushButton:pressed
{
border-style: none;
color: black;
font-size: 14pt;}
QPushButton:disabled
{
border-style: none;
color: white;
font-size: 14pt;}
QLineEdit
{
border-style: solid;
border-width: 2px;
border-color: #99B359;
border-radius: 3px;
font-size: 12pt;
color: black;
}QPushButton#pushButton_ScrollUp
{
border-style: none;}
QPushButton#pushButton_ScrollDown
{
border-style: none;
}
QPushButton#pushButton_ScrollUp:pressed
{
border-style: none;}
QPushButton#pushButton_ScrollDown:pressed
{
border-style: none;}
QPushButton#pushButton_ScrollDown:disabled
{
border-style: none;}
QPushButton#pushButton_ScrollUp:disabled
{
border-style: none;}
QLabel#label_Label1
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#label_Label2
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#label_Label3
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#label_Label4
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#label_Label5
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#label_Label6
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#label_Label7
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#label_Label8
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#Label9
{
border: none;
background-color: white;
color: #99B359;
font-size: 24pt;
}QLabel#label_10
{
border: none;
background-color: white;
color: black;
font-size: 16pt;
}QScrollArea#scroll_Area
{
background: white;
border-style: none;
}QWidget#scrollAreaWidgetContents
{
background: white;
border-style: none;
} -
Did you call that before or after
ui->setupUi(this);
?By the way, please use coding tags (the </> button) to make your code readable.
-
One thing you can do is test your stylesheet directly in Designer to see if there's something wrong with it.
-
Check the generated code to see what it does differently than yours.