python - Impossible to add a background-image in parent QWidget with PyQt5? -


i've been struggling last 2 days... add stretched background image parent qwidget. literally tried dozens of times after searching everywhere i'm still stuck issue. don't use resources (from qt designer). psb :

from pyqt5 import qtcore, qtwidgets, qtgui import sys  class ui_form(qtwidgets.qwidget):  def __init__(self):     qtwidgets.qwidget.__init__(self)     self.setupui(self)   def setupui(self, form):     form.setobjectname("form")     form.resize(860, 619)     form.setstylesheet("qwidget#form {border-image: url(space.png) 0 0 0 0 stretch stretch;}")  

and not work (default bg displayed). when execute this:

        form.setstylesheet("border-image: url(space.png) 0 0 0 0 stretch stretch;") 

all qwidgets children background not want. proves @ least there no problem resource itself. cannot believe basic features setting background image not supported in pyqt5... , appearantly i'm not 1 :

stackoverflow

i've tried make work via qpalette() , works better don't know how make background image stretched =/ :

    image = qtgui.qimage("space.png")     palette = qtgui.qpalette()     palette.setbrush(10, qtgui.qbrush(image))           form.setpalette(palette) 

any idea ?

i found solution (with of qt forum). took @ qt style sheets examples , not find how customize qwidget convert qwidget qmainwindow. got rid of menu bar , status bar because don't need them... works fine qmainwindow :)

class ui_mainwindow(qtwidgets.qmainwindow):  def __init__(self):   super().__init__()          self.setupui(self)  def setupui(self, mainwindow):   mainwindow.setobjectname("mainwindow")   mainwindow.resize(856, 610)   mainwindow.setstylesheet("#mainwindow { border-image: url(space.png) 0 0 0 0 stretch stretch; }")   self.centralwidget = qtwidgets.qwidget(mainwindow)   self.centralwidget.setobjectname("centralwidget") 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -