Results 1 to 4 of 4

Thread: QPainter and refresh window

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPainter and refresh window

    I use PyQt4 and I note that when I change something on a QPainter (example : when I draw a point at different positions), I need to move my mouse (or do some other actions) ON the window if I want to see the modifications.

    Exemple :
    Qt Code:
    1. from socket import WiiSocket
    2. from general import main
    3. import threading
    4. import sys
    5. from PyQt4 import QtGui
    6. import time
    7.  
    8.  
    9. class WiiButtons:
    10. buttons = {"Up" : False,
    11. "Down" : False,
    12. "Left" : False,
    13. "Right" : False,
    14. "Plus" : False,
    15. "Minus" : False,
    16. "Home" : False,
    17. "One" : False,
    18. "Two" : False,
    19. "A" : False,
    20. "B" : False
    21. }
    22.  
    23. def parse(self, data):
    24. if data[:5] != "A1 30":
    25. return
    26.  
    27. data = data[6:].split()
    28. self.buttons["Left"] = bool(int(data[0],16)&0x01)
    29. self.buttons["Right"] = bool(int(data[0],16)&0x02)
    30. self.buttons["Down"] = bool(int(data[0],16)&0x04)
    31. self.buttons["Up"] = bool(int(data[0],16)&0x08)
    32. self.buttons["Plus"] = bool(int(data[0],16)&0x10)
    33. self.buttons["Minus"] = bool(int(data[1],16)&0x10)
    34. self.buttons["Home"] = bool(int(data[1],16)&0x80)
    35. self.buttons["One"] = bool(int(data[1],16)&0x02)
    36. self.buttons["Two"] = bool(int(data[1],16)&0x01)
    37. self.buttons["A"] = bool(int(data[1],16)&0x08)
    38. self.buttons["B"] = bool(int(data[1],16)&0x04)
    39.  
    40. def current(self):
    41. return self.buttons
    42.  
    43.  
    44. if __name__ == "__main__":
    45.  
    46. class MyWidget(QtGui.QWidget):
    47.  
    48. x = 0
    49. y = 0
    50.  
    51. def paintEvent(self, QPaintEvent):
    52. painter = QtGui.QPainter(self)
    53. painter.drawPoint(self.x, self.y)
    54.  
    55.  
    56. def get_info(handler, widget):
    57. buttons = WiiButtons()
    58.  
    59. x = 300
    60. y = 300
    61.  
    62. while handler.state == True:
    63.  
    64. data = handler.receive(32)
    65. if len(data):
    66. buttons.parse(data)
    67. if buttons.current()["Up"]:
    68. widget.y -= 1
    69. widget.repaint()
    70. print "Up"
    71. if buttons.current()["Down"]:
    72. widget.y += 1
    73. widget.repaint()
    74. print "Down"
    75. if buttons.current()["Left"]:
    76. widget.x -= 1
    77. widget.repaint()
    78. print "Left"
    79. if buttons.current()["Right"]:
    80. widget.x += 1
    81. widget.repaint()
    82. print "Right"
    83.  
    84.  
    85. wiimote = main()
    86.  
    87. app = QtGui.QApplication(sys.argv)
    88. widget = MyWidget()
    89. widget.resize(600, 600)
    90. window = QtGui.QMainWindow()
    91. window.setCentralWidget(widget)
    92. window.show()
    93. thread = threading.Thread(None, get_info, None, (wiimote,widget))
    94. thread.start()
    95. app.exec_()
    To copy to clipboard, switch view to plain text mode 

    I guess there is a function or other things for refresh window automatically.

    Thanks.
    Last edited by wysota; 17th February 2009 at 23:10.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.