def __init__(self, theme): QWidget.__init__(self) self.theme = theme self.themename = theme.name self.setMaximumWidth(400) picurl = ":/images/theme.png" self.url = theme.sample_url if theme.sample_pic: picurl = theme.sample_pic pic = FlatButton(picurl, picurl) map = QPixmap(400, 200) p = QPainter(map) p.setRenderHint(QPainter.Antialiasing) p.setRenderHint(QPainter.TextAntialiasing) p.drawImage(QRect(0, 0, 400, 200), QImage(picurl)) p.fillRect(0, 0, map.size().width(), map.size().height(), QColor(69, 187, 230, 125)) if self.url: w = 100 h = 30 p.fillRect(QRect((400 - w) / 2, (200 - h) / 2, w, h), QColor(69, 187, 230, 255)) p.drawRoundedRect(QRect((400 - w) / 2, (200 - h) / 2, w, h), 5, 5) font = QFont() font.setFamily("Arial") font.setBold(True) font.setPixelSize(20) p.setFont(font) p.setPen(QPen(Qt.black)) p.drawText(QRectF(0, 0, 400, 200), "PREVIEW", QTextOption(Qt.AlignHCenter | Qt.AlignVCenter)) pic.clicked.connect(self.clicked) else: pic.setCursor(Qt.ArrowCursor) del p pic.setHoverPixmap(map) pic.setMaximumSize(400, 200) pic.setScaledContents(True) if theme.aktiv: name = QLabel(theme.name.upper() + " (Aktiv)") else: name = QLabel(theme.name.upper()) fnt = name.font() fnt.setPointSize(13) fnt.setBold(True) name.setFont(fnt) layout = QGridLayout() layout.addWidget(pic, 0, 0, 1, 2) layout.addWidget(name, 1, 0) if not theme.aktiv: activate = QPushButton("Activate") layout.addWidget(activate, 1, 1, 1, 1, Qt.AlignRight) activate.clicked.connect(self.activate) self.setLayout(layout)
def createButton(self, icon, text): btn = FlatButton() pmNormal = QPixmap.fromImage(QImage(":/images/module_normal.png")) pmHover = QPixmap.fromImage(QImage(":/images/module_hover.png")) title = QLabel() pal = self.palette() pal.setColor(QPalette.Background, QColor("#999999")) pal.setColor(QPalette.Foreground, QColor("#000000")) title.setPalette(pal) title.setText(text) title.setFixedWidth(90) title.render(pmNormal, QPoint(80, 40)) title.render(pmHover, QPoint(80, 40)) iconLabel = QLabel() iconLabel.setPixmap(QPixmap.fromImage(icon)) iconLabel.render(pmNormal, QPoint(33, 33)) iconLabel.render(pmHover, QPoint(33, 33)) btn.setNormalPixmap(pmNormal) btn.setHoverPixmap(pmHover) return btn