Skip to content

Instantly share code, notes, and snippets.

@chomy
Created December 19, 2013 07:17
Show Gist options
  • Select an option

  • Save chomy/8035540 to your computer and use it in GitHub Desktop.

Select an option

Save chomy/8035540 to your computer and use it in GitHub Desktop.
Sample code of custom widget using PyQt
#!/usr/bin/python
# coding: UTF-8
from PyQt4 import QtGui, QtCore
import sys
class MyWidget(QtGui.QWidget):
def __init__(self):
super(MyWidget, self).__init__()
def paintEvent(self, event):
p = QtGui.QPainter()
p.begin(self)
self.onPaint(p)
p.end()
def onPaint(self, p):
p.drawLine(0,0,self.size().width(),self.size().height())
def main():
app = QtGui.QApplication(sys.argv)
main_window = QtGui.QMainWindow()
main_window.setWindowTitle('Custom Widget Test')
d = MyWidget()
main_window.setCentralWidget(d)
main_window.show()
app.exec_()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment