Пример #1
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # Hello world
        # ブラシ(塗りつぶし)の色を黒に
        painter.setBrush(Qt.black)
        # ペン(線描画)の色も黒に
        painter.setPen(Qt.black)
        # 背景を描く
        # self.rect()はwidgetのサイズを返すので、widget全体を埋める四角形を描画する
        # ペンとブラシの色が黒なので背景色は真っ黒
        painter.drawRect(self.rect())

        # ペン(線描画)の色を白にする
        painter.setPen(Qt.white)

        # フォントサイズを変更する
        font = painter.font()
        # つらさはできるだけ大きく表現したほうが良い
        # 周りが気づくように
        font.setPointSize(80)
        painter.setFont(font)

        # テキストを描画する
        x = 0  # 左端
        y = self.rect().height() * 0.5  # 上下の中心
        painter.drawText(x, y, "TSU☆RA☆I")
Пример #2
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # Hello world
        painter.setBrush(Qt.green)
        painter.setPen(Qt.black)
        painter.drawRect(self.rect())

        painter.drawText(self.rect().width() * 0.5,
                         self.rect().height() * 0.5, "Hello world!")
Пример #3
0
        def paintEvent(self, event):
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(
                self.edit.textCursor().position())
            painter = QPainter(self)
            painter.setPen(Qt.darkGray)
            line_count = 0
            first_pos = -1
            posdiff = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1
                # the top left position of the block in the document
                if posdiff == 0:
                    position_y = self.edit.document().documentLayout(
                    ).blockBoundingRect(block).topLeft().y()
                    if first_pos == -1:
                        first_pos = position_y
                    else:
                        posdiff = position_y - first_pos
                else:
                    position_y += posdiff
                # check if the position of the block is out side of visible area
                if position_y > page_bottom:
                    break
                # we want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)
                    painter.setPen(Qt.black)
                # Draw the line number right justified at the y position of the
                # line. 3 is the magic padding number. drawText(x, y, text)
                painter.drawText(
                    self.width() - font_metrics.width(str(line_count)) - 3,
                    position_y - contents_y + font_metrics.ascent(),
                    str(line_count))
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)
                    painter.setPen(Qt.darkGray)

                block = block.next()

            self.highest_line = line_count
            painter.end()
            QWidget.paintEvent(self, event)
 def paintEvent(self, event):
     with self.lock:
         self.event = event
         rect = event.rect()
         qp = QPainter()
         qp.begin(self)
         radius = min(rect.width(), rect.height()) - 50
         qp.setFont(QFont('Helvetica', 100))
         qp.setPen(QPen(QBrush(QColor(255, 255, 255)), 20))
         
         if self.is_disabled:
             qp.fillRect(rect, self._DISABLED_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._FROWN)
         elif self.is_blackout:
             qp.fillRect(rect, self._BLACKOUT_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._FROWN)
             time_diff = (self.next_whiteout_time - rospy.Time.now()).to_sec()
             if time_diff < 0:
                 time_diff = 0
             time_ratio = time_diff / (self.next_whiteout_time - self.blackout_time).to_sec()
             qp.setFont(QFont('Helvetica', 30))
             qp.drawText(0, rect.height() - 150, rect.width(), 150, QtCore.Qt.AlignCenter, "%.1f sec" % time_diff)
             # 0-360
             if time_ratio > 0:
                 rad = int(math.fmod(time_ratio * 360 + 90*16, 360) * 16)
                 qp.drawArc((rect.width() - radius) / 2, (rect.height() - radius) / 2, radius, radius, 90*16, rad)
         else:
             qp.fillRect(rect, self._OK_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._SMILEY)
         qp.end()
Пример #5
0
 def paintEvent(self, event):
     with self.lock:
         self.event = event
         rect = event.rect()
         qp = QPainter()
         qp.begin(self)
         radius = min(rect.width(), rect.height()) - 50
         qp.setFont(QFont('Helvetica', 100))
         qp.setPen(QPen(QBrush(QColor(255, 255, 255)), 20))
         
         if self.is_disabled:
             qp.fillRect(rect, self._DISABLED_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._FROWN)
         elif self.is_blackout:
             qp.fillRect(rect, self._BLACKOUT_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._FROWN)
             time_diff = (self.next_whiteout_time - rospy.Time.now()).to_sec()
             if time_diff < 0:
                 time_diff = 0
             time_ratio = time_diff / (self.next_whiteout_time - self.blackout_time).to_sec()
             qp.setFont(QFont('Helvetica', 30))
             qp.drawText(0, rect.height() - 150, rect.width(), 150, QtCore.Qt.AlignCenter, "%.1f sec" % time_diff)
             # 0-360
             if time_ratio > 0:
                 rad = int(math.fmod(time_ratio * 360 + 90*16, 360) * 16)
                 qp.drawArc((rect.width() - radius) / 2, (rect.height() - radius) / 2, radius, radius, 90*16, rad)
         else:
             qp.fillRect(rect, self._OK_COLOR)
             qp.drawText(rect, QtCore.Qt.AlignCenter, self._SMILEY)
         qp.end()
Пример #6
0
        def paintEvent(self, event):
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(self.edit.textCursor().position())
            painter = QPainter(self)
            painter.setPen(Qt.darkGray)
            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1
                # the top left position of the block in the document
                position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()
                # check if the position of the block is out side of visible area
                if position.y() > page_bottom:
                    break
                # we want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)
                    painter.setPen(Qt.black)
                # Draw the line number right justified at the y position of the
                # line. 3 is the magic padding number. drawText(x, y, text)
                painter.drawText(
                    self.width() - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) - contents_y + font_metrics.ascent() + self.edit.document().documentMargin(),
                    str(line_count),
                )
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)
                    painter.setPen(Qt.darkGray)

                block = block.next()

            self.highest_line = line_count
            painter.end()
            QWidget.paintEvent(self, event)
Пример #7
0
    def paintEvent(self, event):
        QSlider.paintEvent(self, event)

        curr_value = str(self.value())
        round_value = round(float(curr_value), 4)

        painter = QPainter(self)
        painter.setPen(QPen(QtCore.Qt.white))

        font_metrics = QFontMetrics(self.font())
        font_width = font_metrics.boundingRect(str(round_value)).width()
        font_height = font_metrics.boundingRect(str(round_value)).height()

        rect = self.geometry()
        if self.orientation() == QtCore.Qt.Horizontal:
            horizontal_x_pos = rect.width() - font_width - 5
            horizontal_y_pos = rect.height() * 0.75

            painter.drawText(QtCore.QPoint(horizontal_x_pos, horizontal_y_pos),
                             str(round_value))
            self.x = self.value()
        else:
            pass
        painter.drawRect(rect)