Solved QLabel is snipping after using SetStyleSheet
-
I use QLabels in verticalLayout:
QLabel* label;
label->setWordWrap(true);
label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
label->setMaximumWidth(250);
label->setText(...);
...
expected result: it's okey!
ui->verticalLayout->addWidget(label, 0 , Qt::AlignBottom | Qt::AlignLeft)
then I want to set the properties, for example:
label->setStyleSheet("QLabel {background-color: rgb(255,255,255) }");
result:
why snipping occurs and how to avoid it? Ty for help...
-
Hi and welcome to devnet,
When using a style sheet, the concerned widgets are not rendered by the platform style plugin but by another one that supports style sheet, so the output might not be exactly what you are used to see from your OS.
-
@SHRED4RED
is this really the only stylesheet declaration you set?! -
@raven-worx
Yes. only stylesheet:
Okey, i all the same have the problem with snipping QLabel:code when I add QLabels:
static int x = 1; label->setText(ui->lineEdit->text()); ui->lineEdit->clear(); label->setWordWrap(true); label->setStyleSheet("QLabel { background-color: rgb(0, 0, 0);" "color: rgb(0, 200, 0);" "font: 12pt \"Plantagenet Cherokee\";}" ); label->setTextFormat(Qt::RichText); QSizePolicy policy(QSizePolicy::Fixed , QSizePolicy::Fixed); label->setSizePolicy(policy); label->setAlignment(Qt::AlignLeft); label->setMaximumWidth(250); label->setMinimumHeight(label->sizeHint().height()); if(x % 2 == 0) { ui->verticalLayout_2->addWidget(label,0, Qt::AlignLeft | Qt::AlignBottom); } else { ui->verticalLayout_2->addWidget(label,0, Qt::AlignRight | Qt::AlignBottom); } ++x;
what occurs when I resize MainWindow:
scrollAreaWidgetCotents properties : SizeConstraint SetMinimumSize, sizePolicy: horizontal - Minimum, vertical - Maximum
This problem occurs when I use Layout alignment ! If i don't use it QLabels doesn't snipped
-
QSizePolicy policy(QSizePolicy::Fixed , QSizePolicy::Fixed);
label->setSizePolicy(policy);What happens when you remove this?
-
@raven-worx
If use default QLabel sizePolicy then snipping doesn't occur. But I can't understand what happen ... :( -
Because the size policy you are using explicitly disallows the widget to expand or shrink as needed.
-
@SGaist
Okey i continue testing, and next test are:- just long text
- after long text set empty string or shot string
it's occur if i use Fixed sizePolicy and if don't use it.
Why? - just long text
-
do you see empty area between QLabels? There are the text which are snipped.
If don't use RichText and use Fixed size policy , then all are good. But I nevertheless can't understand how are work this magic.