Pls help on this code, cuz i don't really get the concept. I start a dialog by clicking a button on a qwidget. I also would like to display an image on the aforementiond qdialog by clicking on a different button (img_btn) on the dialog . I have added some code below:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class BasicWidget(QWidget):
def __init__(self, parent=None):
super(BasicWidget, self).__init__()
layout = QVBoxLayout()
self.btn = QPushButton('Show Dialog')
layout.addWidget(self.btn)
self.setLayout(layout)
self.show()
self.btn.clicked.connect(self.showpic)
def showpic(self):
imgshow = PaintPicture()
class PaintPicture(QDialog):
def __init__(self, parent=None):
super(PaintPicture, self).__init__()
layout = QVBoxLayout()
self.img_btn = QPushButton('Enter')
layout.addWidget(self.img_btn)
filename = r'\\some\basic\picture.jpg'
image = QImage(filename )
self.imageLabel = QLabel()
self.imageLabel.setPixmap(QPixmap.fromImage(image))
layout.addWidget(self.imageLabel)
self.setLayout(layout)
self.show()
if __name__ =="__main__":
app = QApplication(sys.argv)
widget = BasicWidget()
sys.exit(app.exec_())
first of all there are two mistakes in your code:
imgshow = PaintPicture()
should beself.imgshow = PaintPicture()
path doesn't work for me like this
filename = r'\\some\basic\picture.jpg'
, but it works this way:filename = r'./some/basic/picture.jpg'
Now, if I understand, you want to open dialog with only "enter" button on it. When you press that button you want image to show on the same dialog, under the button? If so, here's the code: