0

I am working on gui development with PyQt4. I have used stacked widget to geather around 6 widgets in to one ui application. Now I want to set background color and background image to each different widgets. When I set color or image using palette and/or setStyleSheet(),it leaves some margin to each side. I am not getting to how to clear that margin.

If anybody knows kindly post here.

------------------------*********************----------------------------------- @Fabio here is a snippet adds different classes of pages to stackedwidget

def initWidget(self):
    self.stack = QtGui.QStackedWidget()
    layout = QtGui.QVBoxLayout(self)
    layout.addWidget(self.stack)

    self.intropg = Intropage_Gui()
    self.stack.addWidget(self.intropg)

    self.mainpg = MainPage_Gui()
    self.stack.addWidget(self.mainpg)

    self.monitorparams = MonitorParams_Gui()
    self.stack.addWidget(self.monitorparams)

    self.interlockparams = InterlockParams_Gui()
    self.stack.addWidget(self.interlockparams)

    self.setctrls = SetControl_Gui()
    self.stack.addWidget(self.setctrls)

    self.calib = Calib_Gui()
    self.stack.addWidget(self.calib)

    self.commparams = CommParams_Gui()
    self.stack.addWidget(self.commparams)

Here I am adding different widget classes. Now I want to change background color or images of each pages/widget. When i am doing so it leaves some margin all around.

1
  • Please provide some code to explain how the widgets are created and inserted in the stacked widget. Maybe there is some layout that add margins
    – Fabio
    May 3, 2016 at 10:10

1 Answer 1

1

I'm guessing it's because when you do

layout.addWidget(self.stack)

the vertical layout automatically added margins on each side. The default layout margin is 9 for child widgets and 11 for windows per http://doc.qt.io/qt-5/qboxlayout.html

Try

layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.stack)    
layout.setContentsMargins(0, 0, 0, 0)
2
  • @nisarg can you post more code on how you're using initWidget() and maybe a picture of the said margins? setContentsMargins() worked for me
    – Alvin C
    May 5, 2016 at 19:13
  • a new issue i am facing is when i set background color of individual pages it do not appear while execution. But when the same page is executed individually it works well. so there may be some issue with stackedwidget. if know the issue just let me know the solution
    – nisarg
    May 10, 2016 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.