def paintEvent(self,event): super(JoystickPointView,self).paintEvent(event) try: if self._initialized: pass except: self._origPos = self.pos() self._initialized = True qp = QPainter() qp.begin(self) borderWidth = 2 radius = self.height()/2 center = QtCore.QPoint(self.height()/2,self.width()/2) # Outer Circle qp.setRenderHint(QPainter.Antialiasing, True) qp.setPen(QPen(QtCore.Qt.darkGray, borderWidth, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,QtCore.Qt.RoundJoin)) qp.setBrush(QBrush(QtCore.Qt.white, QtCore.Qt.SolidPattern)) qp.drawEllipse(center,radius-borderWidth,radius-borderWidth) # Inner Circle qp.setPen(QPen(QtCore.Qt.lightGray, borderWidth, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,QtCore.Qt.RoundJoin)) qp.setBrush(QBrush(QtCore.Qt.white, QtCore.Qt.SolidPattern)) qp.drawEllipse(center,radius-borderWidth-1,radius-borderWidth-1) qp.end()
def paintEvent(self,event): if not self._initialized: self.placeStickAtCenter() self._initialized = True borderWidth = 1 joyRange = 80 center = QtCore.QPoint(self.height()/2,self.width()/2) qp = QPainter() qp.begin(self) qp.setRenderHint(QPainter.Antialiasing, True) qp.setPen(QPen(QtCore.Qt.lightGray, borderWidth, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,QtCore.Qt.RoundJoin)) if self._mode == "circle": qp.drawEllipse(center,joyRange,joyRange) if self._mode == "square": x = center.x() - joyRange y = center.y() - joyRange width = joyRange * 2 height = joyRange * 2 qp.drawRect(x,y,width,height) qp.end() super(JoystickView,self).paintEvent(event)
def paintEvent(self, event): geom = super(AxisWidget, self).geometry() h = geom.height() w = geom.width() box = QRect(2, 2, w - 4, h - 4) horiz = QLine(2, h / 2, w - 2, h / 2) vert = QLine(w / 2, 2, w / 2, h - 2) targ = QPoint(self._x * (w - 4) / 2 + w / 2, self._y * (h - 4) / 2 + h / 2) plt = super(AxisWidget, self).palette() linebrsh = plt.dark() targetbrsh = plt.highlight() linepen = QPen(linebrsh, 1, Qt.SolidLine, Qt.SquareCap) targetpen = QPen(targetbrsh, 2, Qt.SolidLine, Qt.SquareCap) qp = QPainter() qp.begin(self) qp.setPen(linepen) qp.drawRect(box) qp.drawLine(horiz) qp.drawLine(vert) qp.setPen(targetpen) qp.drawEllipse(targ, 10, 10) qp.end()
def paintEvent(self,event=None): #global mouse_is_pressed w_height = self.frameGeometry().height() w_width = self.frameGeometry().width() if w_height > w_width: diam = w_width else: diam = w_height radius = int(diam / 2) - 10 start_x = w_width/2 - radius start_y = w_height/2 - radius line1_x1 = w_width/2 + radius*0.707 line1_x2 = w_width/2 - radius*0.707 line1_y1 = w_height/2 - radius*0.707 line1_y2 = w_height/2 + radius*0.707 line2_x1 = w_width/2 - radius*0.707 line2_x2 = w_width/2 + radius*0.707 line2_y1 = line1_y1 line2_y2 = line1_y2 painter=QPainter() painter.begin(self) painter.setPen(QPen(Qt.black)) painter.drawLine(line1_x1, line1_y1, line1_x2, line1_y2) #cross painter.drawLine(line2_x1, line2_y1, line2_x2, line2_y2) painter.drawEllipse(start_x,start_y , (radius*2), (radius*2)) if self.mouse_is_pressed == True: painter.setBrush(Qt.blue) rad = self.get_radius(w_width, w_height, self.cursor_pos) pos = self.get_pos(w_width, w_height, self.cursor_pos) if (radius < rad): rad = radius self.draw_arc(painter, w_width, w_height, pos, rad) self.cur_nradius = rad*1.0/radius self.cur_sector = pos else: self.cur_nradius = 0.0 self.cur_sector = 0.0 painter.end() #print self.mouse_is_pressed pass
def paintEvent(self, event): with self.lock: if self.status == 1: color = self._SUCCESS_COLOR elif self.status == 2: color = self._WARN_COLOR else: color = self._UNKNOWN_COLOR rect = event.rect() qp = QPainter() qp.begin(self) radius = min(rect.width(), rect.height()) - 100 qp.setFont(QFont('Helvetica', 100)) qp.setPen(QPen(QBrush(color), 50)) qp.setBrush(color) qp.drawEllipse((rect.width() - radius) / 2, (rect.height() - radius) / 2, radius, radius) qp.end() return
def drawCircle(self, pnt, color, fill=True): p = QPainter(self) p.setPen(color) if (fill): p.setBrush(QBrush(color)) p.drawEllipse(pnt, 3, 3)