def paintSection(self, painter, rect, logicalIndex): ''' The method paint the robot or capability images in the backgroud of the cell. :see: U{QtGui.QHeaderView.paintSection()<https://srinikom.github.io/pyside-docs/PySide/QtGui/QHeaderView.html#PySide.QtGui.PySide.QtGui.QHeaderView.paintSection>} ''' painter.save() QHeaderView.paintSection(self, painter, rect, logicalIndex) painter.restore() if logicalIndex in range(len( self._data)) and self._data[logicalIndex]['images']: if len(self._data[logicalIndex]['images']) == 1: pix = self._data[logicalIndex]['images'][0] pix = pix.scaled(rect.width(), rect.height() - 20, Qt.KeepAspectRatio, Qt.SmoothTransformation) self.style().drawItemPixmap(painter, rect, 5, pix) elif len(self._data[logicalIndex]['images']) > 1: new_rect = QRect(rect.left(), rect.top(), rect.width(), (rect.height() - 20) / 2.) pix = self._data[logicalIndex]['images'][0] pix = pix.scaled(new_rect.width(), new_rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.style().drawItemPixmap(painter, new_rect, 5, pix) new_rect = QRect(rect.left(), rect.top() + new_rect.height(), rect.width(), new_rect.height()) pix = self._data[logicalIndex]['images'][1] pix = pix.scaled(new_rect.width(), new_rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.style().drawItemPixmap(painter, new_rect, 5, pix)
def calcDecorationRect(self, main_rect, image=True): rect = QRect() rect.setX(main_rect.x() + self._idx_icon + self._hspacing) rect.setY(main_rect.y() + self._vspacing) rect.setWidth(self._icon_size if image else main_rect.width() - self._idx_icon) rect.setHeight(self._icon_size) self._idx_icon += self._icon_size + self._hspacing return rect
def mouseMoveEvent(self, QMouseEvent): cursor = QCursor() x = QMouseEvent.x() y = QMouseEvent.y() # if in coords of image and crop status is image then draw the rect if self._rubber is None: return if (x < 1280 and y < 720) and (x > 15 and y > 15) and self.crop_stat == IMG: self._rubber.setGeometry( QRect(self.rub_origin, QMouseEvent.pos()).normalized()) # if in coords of hist and crop status is hist then draw the rect elif (x > 1300 and y > 520) and (x < 1907 and y < 1010) and self.crop_stat == HIST: self._rubber.setGeometry( QRect(self.rub_origin, QMouseEvent.pos()).normalized())
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 drawRect(self): p = QPainter(self) in_bounds = QRect(self.pan_limits[0], self.size - self.tilt_limits[1], self.pan_limits[1] - self.pan_limits[0], self.tilt_limits[1] - self.tilt_limits[0]) p.fillRect(in_bounds, QColor(0, 200, 0, 128)) p.drawRect(in_bounds)
def paint(self, painter, option, index): if index.column() in [0, 3]: return super(GroupsDelegate, self).paint(painter, option, index) button = QStyleOptionButton() r = option.rect x = r.left() + r.width() - 30 y = r.top() + 2 w = 28 h = 14 button.rect = QRect(x, y, w, h) button.text = '+' if index.column() == 1 else '-' button.state = QStyle.State_Enabled QApplication.style().drawControl(QStyle.CE_PushButton, button, painter)
def paintSection(self, painter, rect, logicalIndex): ''' The method paint the robot or capability images in the backgroud of the cell. @see: U{QtGui.QHeaderView.paintSection()<https://srinikom.github.io/pyside-docs/PySide/QtGui/QHeaderView.html#PySide.QtGui.PySide.QtGui.QHeaderView.paintSection>} ''' painter.save() QHeaderView.paintSection(self, painter, rect, logicalIndex) painter.restore() if logicalIndex in range(len(self._data)) and self._data[logicalIndex]['images']: if len(self._data[logicalIndex]['images']) == 1: pix = self._data[logicalIndex]['images'][0] pix = pix.scaled(rect.width(), rect.height() - 20, Qt.KeepAspectRatio, Qt.SmoothTransformation) self.style().drawItemPixmap(painter, rect, 5, pix) elif len(self._data[logicalIndex]['images']) > 1: new_rect = QRect(rect.left(), rect.top(), rect.width(), (rect.height() - 20) / 2.) pix = self._data[logicalIndex]['images'][0] pix = pix.scaled(new_rect.width(), new_rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.style().drawItemPixmap(painter, new_rect, 5, pix) new_rect = QRect(rect.left(), rect.top() + new_rect.height(), rect.width(), new_rect.height()) pix = self._data[logicalIndex]['images'][1] pix = pix.scaled(new_rect.width(), new_rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.style().drawItemPixmap(painter, new_rect, 5, pix)
def mouseReleaseEvent(self, QMouseEvent): cursor = QCursor() x = QMouseEvent.x() y = QMouseEvent.y() if self._rubber is None: return if (x < 1280 and y < 720) and (x > 15 and y > 15) and self.crop_stat == IMG: if not self.frozen_before: self.freeze() a = self.mapToGlobal(self.rub_origin) b = QMouseEvent.globalPos() a = self.wdg_img.mapFromGlobal(a) b = self.wdg_img.mapFromGlobal(b) self._rubber.hide() self._rubber = None pix = QPixmap(self.wdg_img.pixmap()) sx = float(self.wdg_img.rect().width()) sy = float(self.wdg_img.rect().height()) # h 1080 w 1920 sx = self.orig_w / sx sy = self.orig_h / sy a.setX(int(a.x() * sx)) a.setY(int(a.y() * sy)) b.setX(int(b.x() * sx)) b.setY(int(b.y() * sy)) rect_ = QRect(a, b) h_ = rect_.height() w_ = rect_.width() y1, x1, y2, x2 = rect_.getCoords() rospy.loginfo('Img cropped x1 {} y1 {} x2 {} y2{}'.format( x1, y1, x2, y2)) self.log_info('Img cropped x1 {} y1 {} x2 {} y2{}'.format( x1, y1, x2, y2)) self.capture_cropped(x1, y1, x2, y2) elif (x > 1300 and y > 520) and (x < 1907 and y < 1010) and self.crop_stat == HIST: # h 1080 w 1920 if self.hist_status == HSV: cur_hist = self.inner_hist elif self.hist_status == LUV: cur_hist = self.inner_luv_hist # if not self.frozen_before: # self.freeze() a = self.mapToGlobal(self.rub_origin) b = QMouseEvent.globalPos() a = cur_hist.mapFromGlobal(a) b = cur_hist.mapFromGlobal(b) self._rubber.hide() self._rubber = None pix = QPixmap(cur_hist.pixmap()) sx = float(cur_hist.rect().width()) sy = float(cur_hist.rect().height()) # h 1080 w 1920 if self.hist_status == HSV: sx = self.hist_hsv_orig_w / sx sy = self.hist_hsv_orig_h / sy elif self.hist_status == LUV: sx = self.hist_lab_orig_w / sx sy = self.hist_lab_orig_h / sy a.setX(int(a.x() * sx)) a.setY(int(a.y() * sy)) b.setX(int(b.x() * sx)) b.setY(int(b.y() * sy)) rect_ = QRect(a, b) h_ = rect_.height() w_ = rect_.width() # y1,x1,y2,x2 = rect_.getCoords() x1, y1, x2, y2 = rect_.getCoords() rospy.loginfo('Hist cropped x1 {} y1 {} x2 {} y2 {}'.format( x1, y1, x2, y2)) self.log_info('Hist cropped x1 {} y1 {} x2 {} y2 {}'.format( x1, y1, x2, y2)) if self.select_status == HIST_SELECTION: self.select_hist(x1, y1, x2, y2, h_, w_, self.hist_status) elif self.select_status == HIST_DESELECTION: self.deselect_hist(x1, y1, x2, y2, self.hist_status) else: if self._rubber is not None: self._rubber.hide() self._rubber = None self.crop_stat = 0
def _widget_contains(self, widget, point): topleft = widget.mapToGlobal( widget.mapFromParent(widget.geometry().topLeft())) rect = QRect(topleft, widget.geometry().size()) return rect.contains(point)
def _handle_clear_button_clicked(self, checked): self.table_view.setSelection(QRect(0, 0, self._datamodel._message_limit, self._datamodel._message_limit), QItemSelectionModel.Select) self._delete_selected_rows()
def redraw(self, event): """ Draw timeline's "cells" (ie. boxes that represent seconds). Taken from robot_monitor.message_timeline.on_paint @deprecated: This way (using QPainter) didn't work as intended. """ #super(TimelineView, self).paintEvent(event) # painter = QPainter(self) ## This yields warning that says: ## "QPainter::begin: Widget painting can only begin as a result of a paintEvent" painter = QPainter() painter.begin(self.viewport()) pen = QPen( Qt.black, 2) #, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) # Needs modified. painter.setPen(pen) is_enabled = self.isEnabled() #(width_tl, height_tl) = self.size() qsize = self.size() width_tl = qsize.width() height_tl = qsize.height() length_tl = self._max_num_seconds + 1 - self._min_num_seconds rospy.logdebug('paintEvent is_enabled=%s length_tl=%d', is_enabled, length_tl) value_size = width_tl / float(length_tl) for i in xrange(0, length_tl): brush = None color_index = i + self._min_num_seconds if (is_enabled): qcolor = self._color_callback(color_index) else: qcolor = QColor('grey') end_color = QColor(0.5 * QColor('red').value(), 0.5 * QColor('green').value(), 0.5 * QColor('blue').value()) #painter.setBrush(qcolor) painter.setBrush(QBrush(qcolor)) start = i * value_size end = (i + 1) * value_size rect = QRect(start, 0, end, height_tl) # dc.GradientFillLinear(wx.Rect(start, 0, end, height_tl), # qcolor, end_color, wx.SOUTH) rospy.logdebug('paintEvent i=%d start=%s end=%s height_tl=%s', i, start, end, height_tl) #painter.fillRect(QRect(start, end, 100, height_tl), qcolor) painter.fillRect(rect, qcolor) if (i > 0): # dc.SetPen(wx.BLACK_PEN) pen.setColor(Qt.black) # dc.DrawLine(start, 0, start, height_tl) painter.drawLine(start, 0, start, height_tl) size_marker = QSize(20, 20) marker_x = ( (self._xpos_marker - 1) * value_size + (value_size / 2.0) - (self._timeline_marker.actualSize(size_marker).width() / 2.0)) # dc.DrawBitmap(self._timeline_marker, marker_x, 0, True) qrect = QRect(marker_x, 0, size_marker.width(), size_marker.height()) self._timeline_marker.paint(painter, qrect) rospy.logdebug(' paintEvent marker_x=%s', marker_x) painter.end()
def draw_arc(self,qp, w_width, w_height, pos, rad): start_x = w_width/2 - rad start_y = w_height/2 - rad rectangle = QRect(start_x,start_y,(rad*2),(rad*2)) qp.drawPie(rectangle, (45+90*pos)*16, 90*16)
def _widget_contains(self, widget, point): topleft = widget.mapToGlobal(widget.mapFromParent(widget.geometry().topLeft())) rect = QRect(topleft, widget.geometry().size()) return rect.contains(point)