PySide, dynamically loaded UI and PyQtGraph

801 views
Skip to first unread message

Sébastien Celles

unread,
May 18, 2014, 5:07:14 AM5/18/14
to pyqt...@googlegroups.com
Hello,

I'm trying to load a .ui dynamically using PySide QUiLoader

I did

from PySide import QtCore, QtGui, QtUiTools
from PySide.QtGui import *
from PySide.QtCore import *

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui

class PlotWidget(QWidget):
    def __init__(self, parent):
        super(TimelinePane, self).__init__()
        print '\tPlotWidget init 1' # This doesn't print.
        
class MainWindow(QtGui.QDialog):
    def __init__(self, parent = None):
        super(MainWindow, self).__init__(parent)
        loader = QtUiTools.QUiLoader()
        
        #loader.registerCustomWidget(PlotWidget)
        
        path = os.path.dirname(os.path.abspath(__file__))
        uiFile = os.path.join(path, "mainwindow.ui")
        self.ui = loader.load(uiFile)
            
    def show(self):
        self.ui.show()


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    d = MainWindow()
    d.show()
    app.exec_()

You can see also as attachment mainwindow.ui
I have promote a graphicsView to a personnal class "PlotWidget"
<widget class="PlotWidget" name="graphicsView"/>

but I get the following message
"QFormBuilder was unable to create a custom widget of the class 'PlotWidget'; defaulting to base class 'QGraphicsView'."
but a QGraphicsView appears instead of my PlotWidget

If I uncomment 
loader.registerCustomWidget(PlotWidget)
I get these warning messages
"QFormBuilder was unable to create a custom widget of the class 'PlotWidget'; defaulting to base class 'QGraphicsView'."
"Empty widget item in QHBoxLayout 'horizontalLayout_6'."
Designer: The creation of a widget of the class '' failed.
Designer: The creation of a widget of the class '' failed.
Designer: The creation of a widget of the class '' failed.

and my PlotWidget doesn't appears


I would prefer to have a dynamically loaded ui (with .ui file)
instead of generating code with pyside-uic


I really hope you can help me


Kind regards

Sébastien

mainwindow.ui

amdo...@gmail.com

unread,
May 20, 2014, 3:10:04 PM5/20/14
to pyqt...@googlegroups.com
I might be missing it, but it doesn't look like you actually reference the pyqtgraph plot widget class anywhere, as your PlotWidget doesn't actually inherit the pyqtgraph one. I think simply changing your class definition to:

class PlotWidget(pg.PlotWidget):

and then enabling the custom widget line might be enough. Hopefully that is enough to push you in the right direction. I can tell you that am able to use the UI Loader for my application by a similar method without issues.

scls

unread,
May 20, 2014, 3:19:26 PM5/20/14
to pyqt...@googlegroups.com
Thanks a lot...

I've just fixed this issue using:

class PlotWidget(pg.PlotWidget):
    def __init__(self, parent):
        super(PlotWidget, self).__init__()
        print '\tPlotWidget init 1' # This doesn't print.

Reply all
Reply to author
Forward
0 new messages