Exemplo n.º 1
0
    def _make_tabs_button(self, side_widgets, side_icons):

        if len(side_widgets) != len(side_icons):
            raise Exception(
                "Bad parameters : len(side_widgets) ({}) != len(side_icons) ({})"
                .format(len(side_widgets), len(side_icons)))

        layout = QVBoxLayout()

        self._side_icons = []

        ndx = 0
        for w in side_widgets:

            resource_name = side_icons[ndx]
            pixmap = QPixmap(os.path.join(resource_dir, resource_name))
            icon = QIcon(pixmap)
            self._side_icons.append(icon)

            b = QToolButton()
            b.setIcon(icon)
            b.setIconSize(pixmap.rect().size())
            b.setMaximumWidth(pixmap.rect().width() + 6)

            b.clicked.connect(self.signal_mapper_tab_changed.map)
            self.signal_mapper_tab_changed.setMapping(b, ndx)

            layout.addWidget(b)
            layout.setStretch(ndx, 1)
            ndx += 1

        layout.addStretch()

        return layout
Exemplo n.º 2
0
    def drawIconWithShadow(icon, rect, p, iconMode, radius, color, offset):
        cache = QPixmap()
        pixmapName = "icon {0} {1} {2}".format(icon.cacheKey(), iconMode, rect.height())

        if not QPixmapCache.find(pixmapName, cache):
            px = icon.pixmap(rect.size())
            cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
            cache.fill(Qt.transparent)

            cachePainter = QPainter(cache)
            if iconMode == QIcon.Disabled:
                im = px.toImage().convertToFormat(QImage.Format_ARGB32)
                for y in range(im.height()):
                    scanLine = im.scanLine(y)
                    for x in range(im.width()):
                        pixel = scanLine
                        intensity = qGray(pixel)
                        scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel))
                        scanLine += 1
                px = QPixmap.fromImage(im)

            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1), QImage.Format_ARGB32_Premultiplied)
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(QPoint(radius, radius), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            # todo : blur image
            blurPainter.end()

            tmp = blurred

            # blacken the image
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp)

            # Draw the actual pixmap...
            cachePainter.drawPixmap(QPoint(radius, radius) + offset, px)
            QPixmapCache.insert(pixmapName, cache)

        targetRect = cache.rect()
        targetRect.moveCenter(rect.center())
        p.drawPixmap(targetRect.topLeft() - offset, cache)
Exemplo n.º 3
0
def make_tool_button(filename):

    res_path = os.path.join(resource_dir, filename)
    if filename not in resources_cache:
        if not os.path.exists(res_path):
            raise Exception("Can't find resource {}".format(res_path))

        pixmap = QPixmap(res_path)
        icon = QIcon(pixmap)
        resources_cache[filename] = (pixmap, icon)

    pixmap, icon = resources_cache[filename]
    b = QToolButton()
    b.setIcon(icon)
    b.setIconSize(pixmap.rect().size())
    b.setMaximumWidth(pixmap.rect().width() + 6)

    return b
Exemplo n.º 4
0
    def initUI(self):
        self.grid = QGridLayout()
        self.setLayout(self.grid)

        teamnames = json_reader.readJSON('teams.json')

        i = 0
        j = 0
        for team in teamnames:
            tbutton = QPushButton(team['name'])
            team_pic = QPixmap("%s.jpg"%team['name'])
            tbutton.setIcon(QIcon(team_pic))
            tbutton.setIconSize(team_pic.rect().size())
            tbutton.clicked.connect(lambda t=team: self.chooseTeam(t))
            self.grid.addWidget(tbutton, i % 10, j)
            i += 1
            j = j + 1 if i % 10 == 0 else j # this is the dumb
Exemplo n.º 5
0
def gradientpixmap(pm):
  """
  @param  pm  QPixmap
  @return  QPixmap
  """
  # http://www.qtcentre.org/threads/4246-QGraphicsPixmapItem-modifying-the-alpha-channel-of-a-QPixmap
  # http://www.qtcentre.org/threads/37866-QPainter-fill-rect-with-gradient
  if not pm.isNull():
    w = pm.width()
    h = pm.height()
    if w and h:
      gr = getgradient(0, 0, w, h)
      #gr = QLinearGradient(alpha.rect().topLeft(), alpha.rect().bottomRight())
      alpha = QPixmap(w, h)
      p = QPainter(alpha)
      p.fillRect(alpha.rect(), gr)
      p.end()
      pm.setAlphaChannel(alpha)
Exemplo n.º 6
0
 def paintEvent(self, event):
     painter = QStylePainter(self)
     painter.setPen(self.palette().color(QPalette.Text))
     # Draw the combobox frame, focus rect, selected etc.
     opt = QStyleOptionComboBox()
     self.initStyleOption(opt)
     opt.currentText = ""  # Don't draw the raw HTML
     painter.drawComplexControl(QStyle.CC_ComboBox, opt)
     # Draw the icon and text
     painter.drawControl(QStyle.CE_ComboBoxLabel, opt)
     # Draw the HTML
     self.label.setText(self.currentText())
     self.label.adjustSize()
     pixmap = QPixmap(self.label.width(), self.label.height())
     pixmap.fill(Qt.transparent)
     self.label.render(pixmap, renderFlags=QWidget.RenderFlags(0))
     rect = QRect(opt.rect)
     y = (rect.height() - self.label.height()) / 2
     rect.setX(self.fontMetrics().width("n"))
     rect.setY(y)
     rect.setHeight(pixmap.height())
     rect.setWidth(pixmap.width())
     painter.drawPixmap(rect, pixmap, pixmap.rect())