Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt5: Gtk-CRITICAL **: IA__gtk_widget_style_get: assertion 'GTK_IS_WIDGET (widget)' failed

I'm getting this error with PyQt5, and I think I get this error only when I use QTextEdit. I tried using QLineEdit in the place of QTextEdit and it worked without problem. Using QTextEdit when I open the program I get that error and the program runs very slow. Error:(python:4843): Gtk-CRITICAL **: IA__gtk_widget_style_get: assertion 'GTK_IS_WIDGET (widget)' failed

import sys
from PyQt5.QtWidgets import (QWidget, QLabel, QLineEdit, 
    QTextEdit, QGridLayout, QApplication)


class Example(QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()


    def initUI(self):

        title = QLabel('Title')
        author = QLabel('Author')
        review = QLabel('Review')

        titleEdit = QLineEdit()
        authorEdit = QLineEdit()
        reviewEdit = QTextEdit()

        grid = QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(title, 1, 0)
        grid.addWidget(titleEdit, 1, 1)

        grid.addWidget(author, 2, 0)
        grid.addWidget(authorEdit, 2, 1)

        grid.addWidget(review, 3, 0)
        grid.addWidget(reviewEdit, 3, 1, 5, 1)

        self.setLayout(grid) 

        self.setGeometry(300, 300, 350, 300)
        self.setWindowTitle('Review')   
        self.show()


if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
like image 903
kushtrimh Avatar asked Feb 11 '16 22:02

kushtrimh


1 Answers

I found a solution for this problem. Changing the style of the application didn't show the error and everything worked properly.

Corrected Code:

if __name__ == '__main__':

    app = QApplication(sys.argv)
    app.setStyle("fusion") #Changing the style
    ex = Example()
    sys.exit(app.exec_())

More about styles here: http://doc.qt.io/qt-5/gallery.html

like image 76
kushtrimh Avatar answered Nov 02 '22 16:11

kushtrimh