simple drawing with pyqt on a QGraphicsview -


i'm looking simple way draw line on widget within main window of qt application. designed qtdesigner main window qgraphicsview , button. when pressing button, line should drawn in graphics view. isn't there simple way so. qgraphicsview right choice drawing? read dozents of articles , found no solution. here code in short:

import sys import mainwindowui pyqt4.qtcore import * pyqt4.qtgui import *  class mainwindow(qmainwindow, mainwindowui.ui_mainwindow):     def __init__(self, parent=none):         super(mainwindow, self).__init__(parent)         self.setupui(self)          self.connect(self.pushbutton1, signal("clicked()"), self.pb1_pressed)      def pb1_pressed(self):         # here want draw  line on qgraphicswidget:          # simple like: graphview.line(x1,y1,x2,y2) 

i saw lot of complicated looking solutions , tried lot, e.g. overwriting paintevent using qpainter got errors "qpainter::begin: paint device returned engine == 0, type: 1" , don't know how if right way. can please give me simple solution? thank in advance.

dieter

the qgraphicsview widget used display content of qgraphicsscene assume have qgraphicsscene. if so, can draw line on qgraphicsscene in way:

scene.addline(qlinef(x1, y1, x2, y2)) 

where scene reference qgraphicsscene instance.

http://doc.qt.io/qt-4.8/qgraphicsscene.html#addline


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -