from enum import IntEnum
from PySide2 import QtWidgets, QtCore, QtGui
from PySide2.QtWidgets import QMessageBox
import os
from PySide2.QtWidgets import*
from PySide2.QtGui import*
from PySide2 import QtCore
class DockWidget(QtWidgets.QWidget):
widget_for = 1234
def __init__(self, iface):
super().__init__(iface)
self.iface = iface
#self.image = Slika()
self.layout = QtWidgets.QVBoxLayout()
self.model = QtWidgets.QFileSystemModel()
self.model.setRootPath(QtCore.QDir.rootPath())
self.tree = QtWidgets.QTreeView()
self.tree.setModel(self.model)
self.tree.setRootIndex(self.model.index(QtCore.QDir.currentPath()))
self.tree.clicked.connect(self.Slika)
self.layout.addWidget(self.tree)
self.setLayout(self.layout)
def Slika(self, index):
ext = [".jpg", ".png", ".pdf"]
indexItem = self.model.index(index.row(), 0, index.parent())
file = self.model.filePath(indexItem)
#self.model.setRootPath(file)
if file.endswith(tuple(ext)):
index = self.tree.currentIndex()
file_path = self.model.filePath(index)
self.window = QWidget()
self.window.setWindowTitle("View Image")
self.picture = QPixmap(file_path)
self.label = QLabel(self.window)
self.label.setPixmap(self.picture)
self.label.setGeometry(QtCore.QRect(10, 40, self.picture.width(), self.picture.height()))
#self.window.resize(self.picture.width()+20, self.picture.height()+100)
self.window.show()
else:
try:
try:
try:
with open(file ,'r') as f:
tekst = f.read()
fileName = QtCore.QFileInfo(file).fileName()
self.iface.setText(tekst)
except UnicodeDecodeError as type_error:
QMessageBox.information(self, "Message", "Mozete otvoriti samo tekstualne fajlove i slike.")
except PermissionError as not_found:
pass
except FileNotFoundError as not_found:
pass
I have already set self.central_widget = QtWidgets.QTabWidget(self) in my mainwindow, text is not a problem only picture is