I have PyQt application which used to display large data into qplain textedit. I am facing issue or doing some fundamental mistake. it is my first qt project so i did some blunder
Main issue
- I am able to load data and it work well follow below approach. QPlainTextEdit consume large memory for large string But suddenly after 2 to 3 mintue pyqt application got crashed with killed message and not any other info. without any operation (or click)
I have checked cpu utilization and memory usage was also low. any idea to debug/module which can provide detailed info.
I have tried to simulate all whole and create runable program and have following query
can I pass app argument to class
Fin class does not invoking eventfilter
Overview: I have written Finclass which inherits QMainWindow mainwidget is generated when we insert tab. So purpose was, toolbar will common for all tab and create widget for each tab.
I hope I am able to provide some context
#!/usr/bin/env python
import os
import sys
import PySide2
print (PySide2.__file__)
from PySide2.QtCore import QEvent, QSize
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (QDesktopWidget, QMainWindow, QSizePolicy, QWidget, QVBoxLayout)
from PySide2.QtWidgets import (QPlainTextEdit, QApplication, QSplitter, QTabWidget, QToolBar)
class MainWidget(QWidget):
def __init__(self, app):
self.app = app
super().__init__()
## set variable an pass data model object which contain file path
def create_widget(self):
self.create_violation_text()
main_window = QVBoxLayout()
main_layout = QSplitter(Qt.Vertical)
main_layout.addWidget(self.plain_textedit)
# creating widgeth object as main window does not
# add layout direct to own layout
main_window.addWidget(main_layout)
blk_window = QWidget()
blk_window.setLayout(main_window)
return blk_window
def create_violation_text(self):
"""
creating main violation window which contain all violations
"""
self.plain_textedit = QPlainTextEdit()
self.plain_textedit.setLineWrapMode(QPlainTextEdit.NoWrap)
self.plain_textedit.setStyleSheet(
"""QPlainTextEdit {font-size: 14pt;
font-family: Courier;}""")
self.plain_textedit.setReadOnly(True)
self.plain_textedit.setMouseTracking(True)
self.plain_textedit_format = self.plain_textedit.currentCharFormat()
self.plain_textedit.setCursorWidth(5)
self.plain_textedit.viewport().installEventFilter(self)
self.plain_textedit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
def eventFilter(self, obj, event):
print ("event", obj)
if obj is self.plain_textedit.viewport() and event.type() == QEvent.MouseButtonPress:
print ("text edit event")
return super().eventFilter(obj, event)
class FinWindow(QMainWindow):
def __init__(self, app):
super().__init__()
self.width = 1100
self.height = 700
self.set_main_window()
self.blk_obj = MainWidget(app)
self.app = app
def set_main_window(self):
"""
Setting main window position
"""
self.setWindowTitle("GUI %s" % (os.path.abspath(__file__)))
self.setFixedSize(QSize(self.width, self.height))
wid = QDesktopWidget()
screen_width = wid.screen().frameGeometry().width()
screen_height = wid.screen().frameGeometry().height()
self.setGeometry(screen_width / 2 - self.width / 2,
screen_height / 2 - self.height / 2,
self.width, self.height)
def create_menu(self):
"""
Adding toolbar option
:return:
"""
self.toolbar = QToolBar()
def eventfilter(self):
print ("finale filter")
def create_window(self):
self.create_menu()
main_layout = QVBoxLayout()
main_layout.addWidget(self.toolbar)
self.tab_widget = QTabWidget()
self.tab_widget.tabBar().setObjectName("mainTab")
self.tab_widget.addTab(self.blk_obj.create_widget(), "test")
main_layout.addWidget(self.tab_widget)
self.window = QWidget()
self.window.setLayout(main_layout)
self.setCentralWidget(self.window)
def run(self):
self.create_window()
self.show()
self.app.exec_()
if __name__ == '__main__':
app = QApplication()
fin = FinWindow(app)
fin.run()
