Created
December 19, 2013 07:17
-
-
Save chomy/8035540 to your computer and use it in GitHub Desktop.
Sample code of custom widget using PyQt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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