Qt 4: How to set an external border for a QWidget so that its internal widgets are not affected?

I have a rather strange problem. I have a QWidget with a QHBoxLayout . The layout contains two QLabels . I want to set the border for the entire widget. I am using a stylesheet:

  "padding: 10px;" "border-style: solid;" "border-width: 3px;" "border-radius: 7px;" 

But here's the problem: this style applies to both QLabels and completely breaks the layout. I only need an external window to have a border, not shortcuts. Any ideas?

Thanks in advance!

+7
source share
2 answers

Using

 .QWidget { // your css rules } 

.QWidget will only apply CSS to classes that are EXACTLY QWidget and do not inherit QWidget

You can also use the object name selector

 #YourWidgetObjectName { // your css rules } 

Both solutions do not apply the rules to other widgets (even inside)

+7
source

Style sheets will work recursively. If you apply a stylesheet to the Application, it will be applied to all widgets inside it. You may need to specify what you want to apply the stylesheet to?

Logics

should be something like this.

 QHBoxLayout#layoutbox { background-color: red; border-style: outset; border-width: 2px; border-radius: 10px; border-color: beige; font: bold 14px; min-width: 10em; padding: 6px; } 
+7
source

All Articles