Pregunta

I am using Mark Summerfield's Rapid GUI programming book, which was written for PyQt4, and I am using PyQt5. Some things must be different.

Can anybody see why this is failing on my Linux machine that runs Ubuntu 13.04? It runs on Mint 15 but sometimes ends with a segmentation fault. I think it has to do with the difference between PyQt4 and PyQt5, and I have been looking into the C++ implementation at the qt-project.org website. So far I can tell that QVBoxLayout does inherit from QDialog, and it does have a setLayout function. However, commenting out the last line in the _init_ function will allow the program to run without crashing, but also without any widgets added to the QDialog box.

import sys
import PyQt5.QtCore
import PyQt5.QtGui
import PyQt5.QtWidgets

class Form(PyQt5.QtWidgets.QDialog):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.browser = PyQt5.QtWidgets.QTextBrowser()
        self.lineEdit = PyQt5.QtWidgets.QLineEdit("default statement here")
        self.lineEdit.selectAll()
        layout = PyQt5.QtWidgets.QVBoxLayout()
        layout.addWidget(self.browser)
        layout.addWidget(self.lineEdit)
        self.setLayout(layout)    # <--- program seems to crash here



app = PyQt5.QtWidgets.QApplication(sys.argv)
form = Form()
form.show()
app.exec_()

I get an initial error message like this, repeated about 10 times:

(python3:9896): Gtk-CRITICAL **: IA__gtk_widget_style_get: assertion `GTK_IS_WIDGET (widget)' failed

Then it is followed by the following block, which repeats until I kill the program:

QXcbShmImage: shmget() failed (22) for size -524284 (65535x65535)
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::translate: Painter not active
QPainter::save: Painter not active
QPainter::setClipRect: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::restore: Unbalanced save/restore
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::setClipRect: Painter not active
[etc, etc, etc...]
¿Fue útil?

Solución

The problem is the size of the QTextBrowser.

See this bug:

https://bugreports.qt-project.org/browse/QTBUG-32527

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top