Can't call another class
paparucino
paparucino at gmail.com
Sat Sep 4 15:45:54 BST 2021
Hello, from ScriptOne I would like to run ScriptTwo so as to get a
scrollArea with all the widgets I need. I tried to read up but without
success.
If I run ScriptTwo as a single script the scrollArea is displayed correctly.
If I call ScriptTwo from One I get
================================
Traceback (most recent call last):
File "/root/PycharmProjects/ForTestOnly/index.py", line 763, in
Data_Strip
Ui_MainWindow.setupUi (self, self.Strip_Table, anno, month, cursor)
File "/root/PycharmProjects/ForTestOnly/strips.py", line 37, in setupUi
MainWindow.resize (900, 650) # 1700
AttributeError: 'QObject' object has no attribute 'resize'
===========================================
#
#Script One
#
from strips import *
# other stuffs
def Data_Strip(self,limit):
mese = self.Strip_Month_sel.currentText()
anno = self.Strip_Year_sel.currentText()
month = Functions.convert_month_number[mese]
self.Strip_Table = QObject(self.Strip_tab)
self.alphamese = mese
conn = x
cursor = conn.cursor(buffered=True, dictionary=True)
#Ui_MainWindow.setupUi(self, self.Strip_Table, anno, month, cursor)
Ui_MainWindow.setupUi(self, self.Strip_Table)
#
#Script Two
#
class SpecialStyledItemDelegate(QtWidgets.QStyledItemDelegate):
def __init__(self, parent=None):
super().__init__(parent)
self._values = dict()
def add_text(self, text, row):
self._values[row] = text
def initStyleOption(self, option, index):
super().initStyleOption(option, index)
row = index.row()
if row in self._values:
option.text = self._values[row]
option.displayAlignment = QtCore.Qt.AlignCenter
class Ui_MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
def setupUi(self, MainWindow, anno, month, cursor):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(900, 650)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)
self.horizontalLayout.setObjectName("horizontalLayout")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 0, 0))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.layout = QtWidgets.QHBoxLayout(self.scrollAreaWidgetContents)
#self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setObjectName("layout")
##### Many of this: table =
QTableWidget(self.scrollAreaWidgetContents)
self.layout.addWidget(table)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.horizontalLayout.addWidget(self.scrollArea)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
'''
app = QApplication(sys.argv)
window = Ui_MainWindow()
window.show()
app.exec()
'''
More information about the PyQt
mailing list