Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to remove the empty area of QDialog



  • 86569a20-2c15-4b1c-83e8-a2523aa9b4e1-image.png
    My issue is that the yellow area can't be removed.
    I've tried many methods, but they were useless.
    I need your suggestions, thanks.

    def initMainDockWidget(self):
            #============================
            #Global Layout
            #============================
            self.globalLayout = QtWidgets.QVBoxLayout(self)
            self.globalLayout.setContentsMargins(0,0,0,0)
            self.globalLayout.setSpacing(0)
    
            #============================
            #Mian window
            #============================
            self.mainWin = QtWidgets.QMainWindow()
            self.mainWin.setStyleSheet("QMainWindow::pane{border: 0;Padding:0;}")
    
            #================
            #Top Widget
            #================
            self.mainTopWidget = QtWidgets.QWidget()
            self.mainTopWidget.setContentsMargins(0,0,0,0)
            self.mainTopWidget.setMinimumWidth(300)
            self.mainTopWidget.setFixedHeight(35)
    
            #_set mainTopWidget object name
            self.mainTopWidget.setObjectName('controlPanel')
    
    
            #_mainLayout
            self.mainTopLayout = QtWidgets.QVBoxLayout()
            self.mainTopLayout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignVCenter)
            self.mainTopLayout.setSpacing(0)
    
    
            #_QFrame================================================
            self.mainFrame = QtWidgets.QFrame()
            self.mainFrame.setFrameShape(QtWidgets.QFrame.NoFrame)
            self.mainFrame.setLineWidth(0)
            self.mainFrame.setFixedHeight(35)
            self.mainFrame.setContentsMargins(0,0,0,0)
            self.mainFrame.setStyleSheet('QFrame{background-color:rgb(100,0,0);border: 0;Padding:0;}')
            
            #_centrallayout
            self.centralLayout = QtWidgets.QHBoxLayout()
            self.centralLayout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignVCenter)
            self.centralLayout.setSpacing(1)
    
            #_Spacer
            spacerWidth = (self.width()/3)*10
            self.spacerL = QtWidgets.QSpacerItem(spacerWidth, 5, QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
            self.spacerR = QtWidgets.QSpacerItem(spacerWidth, 5, QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
    
            #_GroupManager
            self.btn_GM = QtWidgets.QPushButton('GM', self.mainTopWidget)
            self.btn_GM.setFixedWidth(45)
            self.btn_GM.setFixedHeight(20)
            self.btn_GM.setFont(QtGui.QFont('Caliria', 8))
    
            #_AddGb
            self.btn_addGb = QtWidgets.QPushButton('+', self.mainTopWidget)
            self.btn_addGb.setFixedWidth(45)
            self.btn_addGb.setFixedHeight(20)
            self.btn_addGb.setFont(QtGui.QFont('Caliria',12))
    
            #_QSlider
            self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
            self.slider.setFixedWidth(180)
            self.slider.setPageStep(1)
            self.slider.setSingleStep(10)
            self.slider.setRange(0,100)
    
            #_QLineEdit
            self.le_sliderValue = QtWidgets.QLineEdit('100', self.mainTopWidget)
            self.le_sliderValue.setToolTip('Slider Maximum')
            self.le_sliderValue.setFixedWidth(50)
            self.le_sliderValue.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp("[0-9]*"), self))
            self.le_sliderStep = QtWidgets.QLineEdit('10', self.mainTopWidget)
            self.le_sliderStep.setToolTip('Slider Step')
            self.le_sliderStep.setFixedWidth(20)
            self.le_sliderStep.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp("[0-9]*"), self))
    
    
            #================
            #Setup Central Layout
            #================
            self.centralLayout.addWidget(self.btn_GM)
            self.centralLayout.addItem(self.spacerL)
            self.centralLayout.addWidget(self.btn_addGb)
            self.centralLayout.addWidget(self.slider)
            self.centralLayout.addWidget(self.le_sliderValue)
            self.centralLayout.addWidget(self.le_sliderStep)
            self.centralLayout.addItem(self.spacerR)
    
    
            #================
            #Set Layout
            #================
            #_controlPanel to QFrame
            self.mainFrame.setLayout(self.centralLayout)
            #_Append QFrame
            self.mainTopLayout.addWidget(self.mainFrame)
    
            #_QFrame to the mainTopWidget
            self.mainTopWidget.setLayout(self.mainTopLayout)
    
            
            #_set Central Widget
            self.mainWin.setCentralWidget(self.mainTopWidget)
    
            #_Append mainWin
            self.globalLayout.addWidget(self.mainWin)
    

  • Moderators

    Remove

     self.mainTopWidget.setContentsMargins(0,0,0,0)
    

    and this

    self.mainFrame.setContentsMargins(0,0,0,0)
    

    and set

     self.mainTopLayout.setContentsMargins(0,0,0,0)
    

    In short - use content margins on layouts, not on widgets. They do kinda similar but actually different things. On widgets they are seldom used and 0 is the default anyway.



  • Thank you for help. Solved.


Log in to reply