[PySide] Sub classing question - almost works

Phil phil_lor at bigpond.com
Sat Jun 29 08:53:33 CEST 2013


On 29/06/13 11:36, Phil wrote:
Thank you again for reading this.

I have progress almost to the point where my code is working. The 
DrawTest class displays the drawn yellow line and the empty frame. Now 
all I need is either create an instance of the Frame class or call the 
drawLine function; calling the function would be the better option.

The question is, what parameters do I pass to the drawLine function? I 
know I need self, event and QPainter.

-----------------------------------

from mainwindow import Ui_MainWindow
from PySide import QtCore, QtGui
from frame import Frame

class DrawTest(QtGui.QMainWindow):
     def __init__(self, parent=None):
         super(DrawTest, self).__init__(parent)

         self.ui = Ui_MainWindow()
         self.ui.setupUi(self)

     def buttonClicked(self):
         print("clicked")

     def paintEvent(self, event):
         qp = QtGui.QPainter()
         qp.begin(self)
         pen = QtGui.QPen(QtCore.Qt.yellow, 4)
         qp.setPen(pen)
         self.drawLine(event, qp)
         qp.end()

     def drawLine(self, event, qp):
         qp.drawLine(10, 10, 30, 30)

Frame.dummy()

x = Frame()      # neither of the two following lines work
Frame.drawLine() # what parameters do I need here?


This is the frame class;

--------------------------------

from PySide import QtCore, QtGui

class Frame(QtGui.QFrame):
     def __init__(self, parent=None):
         super(DrawTest, self).__init__(parent)
         self.frame = Frame(self)
         self.setCentralWidget(self.frame)

     def paintEvent(self, event):
         qp = QtGui.QPainter()
         qp.begin(self)
         pen =QtGui.QPen(QtCore.Qt.red, 4)
         qp.setPen(pen)
         self.drawLine(event, qp)
         qp.end()

     def drawLine(self, event, qp):
         qp.drawLine(10, 10, 30, 30)

     def dummy():
         print("dummy has been called")

-- 
Regards,
Phil



More information about the PySide mailing list