11

Situation:
I am working on a Qt4 application constructed in this way (in case parent widgets matter in this issue):

QApplication
   |_ QMainwindow
         |_ QScrollArea (central widget)
               |_ QFrame (child of scroll area)
                     |_ QFrame
                     |      |_ QLabel
                     |            |_ QPixmap
                     |_ QFrame
                     |      |_ QLabel
                     |            |_ QPixmap
                     |_ QFrame
                           |_ ect...

Objective:
I want there to be no margins between the sub-QFrames and their QLabels and equally between QLabels and their QPixmap.

Method:
I have requested to reduce the sub-QFrame’s margins with QFrame.setContentsMargins(0, 0, 0, 0) and with its layout’s QBoxLayout.setSpacing(0). Zero-margin between QLabel and its QPixmap seems to occur naturally.

Problem:
In spite of all this, margins within QFrames persist in showing up: a situation which I have been able to test by applying a Style Sheet to the various widgets.

What can I do?

neydroydrec
  • 6,973
  • 9
  • 57
  • 89

1 Answers1

13

Answer provided on Qt Forum:

The margins' content should be set both on the widget and its layout. Hence:

QWidget *w = new QWidget();
w->setContentsMargins(0, 0, 0, 0);
w->layout()->setContentsMargins(0, 0, 0, 0);
Validus Oculus
  • 2,756
  • 1
  • 25
  • 34
neydroydrec
  • 6,973
  • 9
  • 57
  • 89
  • 3
    In fact, the setContentsMargins has to be executed on the LAYOUT, and if it doesn't work, then an optional parameter is setting the spacing to 0 -> setSpacing(0) to the layout. – Darkgaze Aug 12 '13 at 16:02