Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:13:35+00:00 2026-06-12T18:13:35+00:00

I’m Trying to set the background image (which is located in the same folder

  • 0

I’m Trying to set the background image (which is located in the same folder as the application) of a QGridLayout widget via pyside to no avail I have looked at all the tuts, docs and forum posts regarding stylesheets’ but still i cant figure out what I’m doing wrong.

from PySide.QtCore import *
from PySide.QtGui import *
import sys

class Main(QWidget):

    def __init__(self, parent=None):
        super(Main, self).__init__(parent)

        j = 0
        pos =  [(0, 0), (0, 1), (0, 2), (0, 3),
                (1, 0), (1, 1), (1, 2), (1, 3),
                (2, 0), (2, 1), (2, 2), (2, 3),
                (3, 0), (3, 1), (3, 2), (3, 3),
                (4, 0), (4, 1), (4, 2), (4, 3),
                (5, 0), (5, 1), (5, 2), (5, 3)]

        grid  = QGridLayout(self)
        items = ["one", "Two", 'Three','four','five']

        for e in items:
            picture = ImageLabel("Book.png", self)
            picture.name = e
            picture.setFixedSize(128,128)
            picture.mousepos = str(picture.pos())
            picture.imageClicked.connect(self.anotherSlot)
            grid.addWidget(picture, pos[j][0], pos[j][1])
            j = j + 1
            picture.setToolTip('This is' + str(e) + ' widget')
            picture.imageHovered.connect(self.Item_Hovered)

        self.setStyleSheet("QGridLayout {background-image: url(./image.jpg) }");


    def anotherSlot(self):
        sender = self.sender()
        print "I clicked item " + str(sender.name)

    def Item_Hovered(self):
        sender = self.sender()
        print "I'm Hovering over " + str(sender.name)

class ImageLabel(QLabel):

    imageClicked = Signal(str) # can be other types (list, dict, object...)
    imageHovered = Signal(str)
    imageLeave   = Signal(str)

    def __init__(self, image, parent=None):
        super(ImageLabel, self).__init__(parent)        
        self.setPixmap(image)
        # self.setMouseTracking(True)

    def mousePressEvent(self, event):
        print "from ImageLabel.mousePressEvent()"
        self.imageClicked.emit("Image Clicked")

    def enterEvent(self, event):
        print "from ImageLabel.enterEvent()"
        self.imageHovered.emit("Hovering")

    def leaveEvent(self, event):
        print "from ImageLabel.leaveEvent()"
        self.imageLeave.emit("Hovering No More")


a = QApplication([])
m = Main()
m.show()
sys.exit(a.exec_())

any advice would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:13:37+00:00Added an answer on June 12, 2026 at 6:13 pm

    even if it works you’ll not get the expected result, the only way I achieve correct background paint is overriding paintEvent

    tile = QtGui.QPixmap("x.png")
    
    def paintEvent(self, pe):
        painter = QtGui.QPainter(self)
        painter.drawTiledPixmap(self.rect(), tile)
        super(Console, self).paintEvent(pe)
    

    Console is my class class Console(QtGui.QMainWindow):
    The example applies to the whole window.

    I’m not sure the painter constructor can be moved away from paintEvent

    Update: looks like QPainter needs to be created on each paintEvent

    I’ve found an easiest way without override the paintEvent

    palette = QtGui.QPalette()
    palette.setBrush(QtGui.QPalette.Background, tile)
    self.setPalette(palette)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.