PyQt QScrollArea no scrollarea

2024/11/17 13:40:37

I have

class View(QtWidgets.QLabel):def __init__(self):super(View,self).__init__()self.cropLabel = QtWidgets.QLabel(self)self.label = QtWidgets.QLabel(self)self.ogpixmap = QtGui.QPixmap()fileName = r'C:/Users/user11.HPO-SAMAT/Pictures/Lake.jpg'image = QtGui.QImage(fileName)self.pixmap = QtGui.QPixmap.fromImage(image)self.label.setPixmap(self.pixmap)self.label.adjustSize()

and then I call this class:

class Viewer(QtWidgets.QMainWindow):def __init__(self):super().__init__()self.view = View()self.scroller = QtWidgets.QScrollArea()self.scroller.setWidget(self.view)self.scroller.setWidgetResizable(True)self.scroller.adjustSize()

But QScrollArea does not seem to work (noscrollbar though the image is visible and I can expand QMainWindows to see it entirely) What am I doing wrong ?

Answer

I do not understand so they put several labels inside View, if we remove the labels that are other we get what you want.

class View(QtWidgets.QLabel):def __init__(self, parent=None):super(View,self).__init__(parent)fileName = "/home/qhipa/Pictures/1475777628875.jpg"self.pixmap = QtGui.QPixmap(fileName)self.setPixmap(self.pixmap)class Viewer(QtWidgets.QMainWindow):def __init__(self):super().__init__()self.view = View(self)self.scroller = QtWidgets.QScrollArea(self)self.setCentralWidget(self.scroller)self.scroller.setWidget(self.view)self.scroller.setWidgetResizable(True)self.scroller.adjustSize()

enter image description here

Instead if you want to get several labels, it is better that the View class inherits from QWidget.

class View(QtWidgets.QWidget):def __init__(self, parent=None):super(View,self).__init__(parent)self.setLayout(QtWidgets.QVBoxLayout())self.cropLabel = QtWidgets.QLabel(self)self.label = QtWidgets.QLabel(self)self.layout().addWidget(self.cropLabel)self.layout().addWidget(self.label)self.pixmap = QtGui.QPixmap("/home/qhipa/Pictures/1475777628875.jpg")self.label.setPixmap(self.pixmap)self.label.adjustSize()
https://en.xdnf.cn/q/118797.html

Related Q&A

svg tag scraping from funnels

I am trying to scrape data from here but getting error. I have taken code from here Scraping using Selenium and pythonThis code was working perfectly fine but now I am getting errorwait.until(EC.visibi…

Python search for multiple values and show with boundaries

I am trying to allow the user to do this:Lets say initially the text says:"hello world hello earth"when the user searches for "hello" it should display:|hello| world |hello| earthhe…

Python: create human-friendly string from a list of datetimes

Im actually looking for the opposite of this question: Converting string into datetimeI have a list of datetime objects and I want to create a human-friendly string from them, e.g., "Jan 27 and 3…

Python replace non digit character in a dataframe [duplicate]

This question already has answers here:Removing non numeric characters from a string in Python(9 answers)Closed 5 years ago.I have the following dataframe column>>> df2[Age]1 25 2 35 3 …

PyGame.error in ubuntu

I have problem with pygame and python 3 in ubuntu 12.10. When i tried load an image i got this error: pygame.error: File is not a Windows BMP fileBut in python 2.7 all works fine. I use code from http:…

Firebase Admin SDK with Flask throws error No module named firebase_admin

--- Question closedIt was my mistake, my uWSGI startup script switches to a different virtualenv.--- Original questionIm trying to publish push notifications from my Flask app server to Android APP. Se…

Recursive generator for change money - python

First, thanks for any help. I have this recursive code for counting ways of change from a list of coins and a given amount. I need to write a recursive generator code that presents the ways in every it…

Like button not recording the data [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Python, Pygame, Image manipulation: Restretch a loaded png, to be the texture for an isometric Tile

Im a 17 year old programmer, trying to program an isometric game in python, with pygame. After finishing a tile engine, working with not good looking, gimp-drawn PNGs, I wondered, if it would be possib…

TypeError: list object is not callable [duplicate]

This question already has answers here:TypeError: list object is not callable while trying to access a list(9 answers)Closed 10 years ago.I cant find the problem im facing... this is exactly what the …