Ejemplo n.º 1
0
class CloseComboBoxLabel(QtWidgets.QLabel):
    clicked = QtCore.pyqtSignal()

    def __init__(self, parent=None, wh=None, pixmap=None, close_icon=None, image_icon=None):
        super(CloseComboBoxLabel, self).__init__(parent)

        if wh is None:
            wh = (25, 25)
        self.wh = wh
        self.pixmap = pixmap
        self.close_icon = close_icon
        self.image_icon = image_icon
        self.__style()

    def __style(self):
        self.setMinimumSize(QtCore.QSize(self.wh[0], self.wh[1]))
        self.setMaximumSize(QtCore.QSize(self.wh[0], self.wh[1]))
        self.setMouseTracking(False)
        self.setScaledContents(True)
        self.setAlignment(QtCore.Qt.AlignCenter)
        self.setPixmap(self.pixmap)

        self.close_btn = QtWidgets.QPushButton(self)
        self.close_btn.setFlat(True)
        self.close_btn.setMouseTracking(False)
        self.close_btn.setMinimumSize(QtCore.QSize(int(self.wh[0] / 5), int(self.wh[0] / 5)))
        self.close_btn.setMaximumSize(QtCore.QSize(int(self.wh[0] / 5), int(self.wh[0] / 5)))
        self.close_btn.setIcon(self.close_icon)
        self.close_btn.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))

        self.comb_box = QtWidgets.QComboBox(self)
        self.comb_box.setFocusPolicy(QtCore.Qt.TabFocus | QtCore.Qt.ClickFocus)
        self.comb_box.setFrame(False)
        self.comb_box.setIconSize(QtCore.QSize(16, 16))
        self.comb_box.addItem(self.image_icon, '')
        for c in string.hexdigits[0:10]:
            self.comb_box.addItem(self.image_icon, c)

    def resizeEvent(self, event):
        event.accept()
        self.close_btn.setGeometry(
            self.width()-self.close_btn.width(), 0, self.close_btn.width(), self.close_btn.height()
        )
        self.comb_box.setGeometry(0, self.height()*0.8, self.width(), self.height()/5)

    def mousePressEvent(self, event):
        event.accept()
        self.clicked.emit()
Ejemplo n.º 2
0
class CloseLabel(QtWidgets.QLabel):
    clicked = QtCore.pyqtSignal()

    def __init__(self, parent=None, wh=None, pixmap=None, close_icon=None):
        super(CloseLabel, self).__init__(parent)

        if wh is None:
            wh = (25, 25)
        self.wh = wh
        self.pixmap = pixmap
        self.close_icon = close_icon

        self.__style()
        self.close_btn.clicked.connect(self.close_btn.hide)

    def __style(self):
        self.setMinimumSize(QtCore.QSize(self.wh[0], self.wh[1]))
        self.setMaximumSize(QtCore.QSize(self.wh[0], self.wh[1]))
        self.setMouseTracking(True)
        self.setScaledContents(True)
        self.setAlignment(QtCore.Qt.AlignCenter)
        self.setPixmap(self.pixmap)

        self.close_btn = QtWidgets.QPushButton(self)
        self.close_btn.setFlat(True)
        self.close_btn.setMouseTracking(True)
        self.close_btn.setMinimumSize(QtCore.QSize(int(self.wh[0]/5), int(self.wh[0]/5)))
        self.close_btn.setMaximumSize(QtCore.QSize(int(self.wh[0]/5), int(self.wh[0]/5)))
        self.close_btn.setIcon(self.close_icon)
        self.close_btn.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.close_btn.setGeometry(
            self.width()-self.close_btn.width(), 0, self.close_btn.width(), self.close_btn.height()
        )
        self.close_btn.hide()

    def mousePressEvent(self, event):
        event.accept()
        self.clicked.emit()

    def mouseMoveEvent(self, event):
        if (event.pos().y() <= int(self.width()/5)) and (event.pos().x() >= self.width()-self.close_btn.width()):
            self.close_btn.show()
        else:
            self.close_btn.hide()

    def leaveEvent(self, event):
        event.accept()
        self.closeButton.hide()