📜 ⬆️ ⬇️

Draw your button in QGraphicsScene in PyQt4

It would seem that what could be simpler than a regular button with its standard behavior and the look familiar to the whole world? However, the process of creating your own button is no less interesting than creating a whole application using PyQt4.

Here is an example of creating your own hand-drawn button in QGraphicsScene using QGraphicsWidget.

Recommended for reading by people with experience with PyQt4.

For a start, let's figure out what the button is.
The usual button is, most often, a rectangle with text and / or a picture, the mouse click on which is accompanied by a visual response. The main purpose of the buttons is to respond to a simple click and release event with the mouse pointer (or finger) located in the coordinate field of this button.
')
  1. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  2. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  3. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  4. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  5. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  6. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  7. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  8. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  9. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  10. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  11. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  12. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  13. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  14. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  15. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  16. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  17. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  18. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  19. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  20. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  21. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  22. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  23. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  24. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  25. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  26. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  27. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  28. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  29. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  30. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  31. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  32. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  33. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  34. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  35. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  36. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  37. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  38. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  39. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  40. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  41. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  42. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  43. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  44. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  45. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  46. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  47. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  48. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  49. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  50. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  51. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  52. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  53. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  54. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  55. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  56. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  57. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  58. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  59. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  60. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  61. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  62. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  63. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  64. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  65. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  66. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  67. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  68. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  69. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  70. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  71. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())
  72. # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys class AButton(QtGui.QGraphicsWidget): # mouse_isPressed = False def __init__ ( self , parent = None ): QtGui.QGraphicsWidget. __init__ ( self ) def boundingRect( self ): # # # # . # QRectF, QRect, # . return QtCore.QRectF( 0 , 0 , 40 , 40 ) def paint( self , painter, option, widget = 0 ): # opt = QtGui.QStyleOptionButton() # , # opt.state = ((QtGui.QStyle.State_Sunken if self .mouse_isPressed else QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) # opt.text = self .text() # opt.icon = self .icon() # opt.rect = option.rect # opt.palette = option.palette # QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter) def text( self ): # , , # return QtCore.QString( "hi" ) def icon( self ): # , # # QPixmap QIcon return QtGui.QIcon() def mousePressEvent( self , event): # # self .mouse_isPressed = True self .update() def mouseReleaseEvent( self , event): # self .mouse_isPressed = False # update - , # self .update() if __name__ == "__main__" : app = QtGui.QApplication( sys .argv) # , # scene = QtGui.QGraphicsScene() # button = AButton() # scene.addItem(button) # , # view = QtGui.QGraphicsView(scene) # view.setRenderHint(QtGui.QPainter.Antialiasing) # view.resize( 200 , 100 ) # view.setBackgroundBrush(QtGui.QApplication.palette().background()) view.show() sys .exit(app.exec_())



In my case, this code works fine in PyQt 4.9.1 for Python 2.7.

Of course, this button is far from perfect, but our goal was to understand how to draw your widgets in the graphics area and make them interactive. In general, these are fundamentals, based on which and changing them, you can achieve almost any realization of your plans and practice your work, being a programmer.

Initially, the above code was found on the Internet, written in C ++, safely saved to a computer, and the source is lost. Later, the code itself was rewritten into Python with some features, and the original was removed from the computer.

Thank you for attention.

Source: https://habr.com/ru/post/139933/


All Articles