def paintEvent(self, event): # We need to preserve aspect ratio. Figure out bounding box for # webcam image. im_dx = self._image.width() im_dy = self._image.height() im_ratio = im_dx / float(im_dy) wi_dx = self.width() wi_dy = self.height() wi_ratio = wi_dx / float(wi_dy) if wi_ratio > im_ratio: # Need to pad on sides xmin = wi_dx / 2. - wi_dy / 2. * im_ratio ymin = 0. width = wi_dy * im_ratio height = wi_dy else: # Need to pad on top/bottom xmin = 0. ymin = wi_dy / 2. - wi_dx / 2. / float(im_ratio) width = wi_dx height = wi_dx / float(im_ratio) painter = QtGui.QPainter(self) painter.drawImage(QtCore.QRect(xmin, ymin, width, height), self._image)
def _update_intensity_label(self, x, y): lbl = self._intensity_label(x, y) self.label_widget.setText(lbl) fm = self.label_widget.fontMetrics() w, h = fm.width(lbl), fm.height() g = QtCore.QRect(20, self.central_widget.geometry().height() - h, w, h) self.label_widget.setGeometry(g)