Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from PyQt5.QtWidgets import (QApplication, QWidget, QComboBox, QDialog,
  3. QDialogButtonBox, QFormLayout, QGridLayout, QGroupBox, QHBoxLayout,
  4. QLabel, QLineEdit, QMenu, QMenuBar, QPushButton, QSpinBox, QTextEdit,
  5. QVBoxLayout, QGraphicsView, QGraphicsScene, QGraphicsItem, QGraphicsPixmapItem)
  6. from PyQt5.QtGui import (QIcon, QPixmap, QBrush, QPen, QColor)
  7. from PyQt5 import QtCore
  8. from PyQt5.QtCore import (QLineF, QPointF, QRectF, Qt)
  9.  
  10. import sys
  11. import os
  12. import re
  13.  
  14.  
  15. class Test_graphics(QGraphicsItem):
  16. def __init__(self):
  17. super(Test_graphics, self).__init__()
  18. self.time = 0
  19. self.a = 1
  20.  
  21. def paint(self, painter, option, widget):
  22. painter.setPen(Qt.black)
  23. i = self.time
  24. painter.drawEllipse(i, i, 10, 10)
  25.         #下の関数を入れないとうまく表示が更新されない。
  26. def boundingRect(self):
  27. return QRectF(0,0,400,400)
  28.  
  29. def redraw(self):
  30. if self.time == 0:
  31. self.a = 1
  32. elif self.time >= 390:
  33. self.a = -1
  34. else:
  35. pass
  36. x = self.time + 10*self.a
  37. self.time = x
  38. self.update()
  39.  
  40. class MainWindow(QWidget):
  41.  
  42. def __init__(self,parent=None):
  43. super(MainWindow, self).__init__(parent)
  44. path = os.path.join(os.path.dirname(sys.modules[__name__].__file__), 'ico.png')
  45. view = QGraphicsView()
  46. scene = QGraphicsScene()
  47. self.item = Test_graphics()
  48. view.setSceneRect(0, 0, 400, 400);
  49. scene.addItem(self.item)
  50. view.setScene(scene)
  51. mainLayout = QVBoxLayout()
  52. mainLayout.addWidget(view)
  53. self.setLayout(mainLayout)
  54. #windowのタイトル変更
  55. self.setWindowTitle("Test App6")
  56.  
  57. def mousePressEvent(self, event):
  58. self.item.redraw()
  59. super(MainWindow, self).mousePressEvent(event)
  60.  
  61. if __name__ == '__main__':
  62. app = QApplication(sys.argv)
  63. path = os.path.join(os.path.dirname(sys.modules[__name__].__file__), 'ico.png')
  64. app.setWindowIcon(QIcon(path))
  65. P = MainWindow()
  66. P.show()
  67. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement