ColinDuquesnoy / QDarkStyleSheet

A dark style sheet for QtWidgets application
Other
2.76k stars 726 forks source link

`QCoreApplication::exec: The event loop is already running` while using `qdarkstyle` and the python debugger `pdb` at the same time #290

Closed bjce closed 2 years ago

bjce commented 2 years ago

First of all, many thanks for rightin this nice package QDarkStyleShee

In this application (running on MacOS 11.2.3), using qdarkstyle and the python debugger pdb at the same time, if we click on the button, the following message appears:

QCoreApplication::exec: The event loop is already running

the message disappears if you comment out line 6 and line 65

Do you have any idea how to fix the problem?

from PySide2 import QtGui
from PySide2 import QtCore
from PySide2.QtWidgets import QWidget, QApplication, QPushButton, QFileDialog
from PySide2.QtCore import QFile, QTextStream

import qdarkstyle

import sys
import os 
import subprocess
from subprocess import call
import pdb

import matplotlib
import matplotlib.pyplot as plt

try:
    matplotlib.rcParams['backend.qt5'] = 'PySide2'
except (KeyError, Exception):
    pass
matplotlib.use('Qt5Agg')

os.environ['QT_MAC_WANTS_LAYER'] = '1'

from IPython.core import ultratb

sys.excepthook = ultratb.FormattedTB(mode='Verbose', color_scheme='Linux', call_pdb=True)

class GUI(QWidget):
    def __init__(self):
        super(GUI, self).__init__()

        self.initUI()

    def initUI(self):

        height_btn = 40 
        width_btn = 350

        button_position_x = 0
        button_position_y = 20 

        button_position_x = button_position_x = 0
        button_position_y = button_position_y + 400
        btn15 = QPushButton('button', self)     
        btn15.clicked.connect(self.Plotfunction)
        btn15.resize(width_btn, height_btn)
        btn15.move(button_position_y, button_position_x)       
        self.show()

    def Plotfunction(self):
        pdb.set_trace()
        print("ok")

def main():

    app = QApplication(sys.argv)
    app.setStyleSheet(qdarkstyle.load_stylesheet())
    ex = GUI()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
bjce commented 2 years ago

Ok, I had to add

app.setStyleSheet(qdarkstyle.load_stylesheet(qt_api='pyside2'))

this solved the problem

Many thanks to the developer / maintainer!