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 496209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:39:53+00:00 2026-05-13T05:39:53+00:00

I want to make image in my QMainWindow so when you click on it

  • 0

I want to make image in my QMainWindow so when you click on it you have a signal translating like qpushbutton I use this:

self.quit=QtGui.QPushButton(self)
self.quit.setIcon(QtGui.QIcon('images/9.bmp'))

But the problem is whene I resize the window qpushbutton resized too but not his icon,

  • 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-05-13T05:39:53+00:00Added an answer on May 13, 2026 at 5:39 am

    Qt won’t stretch your image for you – and it’s best this way. I recommend to keep the pushbutton of a constant size by adding stretchers to the layout holding it. A resizable pushbutton isn’t very appealing visually, and is uncommon in GUIs, anyway.

    To make a clickable image, here’s the simplest code I can think of:

    import sys
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    
    
    class ImageLabel(QLabel):
        def __init__(self, image, parent=None):
            super(ImageLabel, self).__init__(parent)
            self.setPixmap(image)
    
        def mousePressEvent(self, event):
            print 'I was pressed'    
    
    
    class AppForm(QMainWindow):
        def __init__(self, parent=None):
            QMainWindow.__init__(self, parent)
    
            self.create_main_frame()       
    
        def create_main_frame(self):
            name_label = QLabel("Here's a clickable image:")
            img_label = ImageLabel(QPixmap('image.png'))
    
            vbox = QVBoxLayout()
            vbox.addWidget(name_label)
            vbox.addWidget(img_label)
    
            main_frame = QWidget()
            main_frame.setLayout(vbox)
            self.setCentralWidget(main_frame)
    
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        form = AppForm()
        form.show()
        app.exec_()
    

    Just replace image.png with your image filename (acceptable format by QPixmap) and you’re set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make JButton from image. But when i do it like this:
I want to make the joomla articles intro image to behave like the read
I want to make Java JDialog appear like it is presented in the image
I have 4 image views on a view.I want to make the 4 images
I want to make an image viewer (for my website) like the one in
I want make something like animation. I have four UIImageView (names: IW1, IW2, IW3,
I have list of images in json format, and want to make an image
I am working on Silverlight application and I want to make Image mousedouble click
I want to make small image browser like the one used on Myfonts.com (
I want to make a javascript image loader. This is what I try :

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.