class ButtonLineEdit(QLineEdit):
    buttonClicked = pyqtSignal()

    def __init__(self, parent=None):
        super(ButtonLineEdit, self).__init__(parent)

        self.setPlaceholderText("Search")

        self.btnSearch = QToolButton(self)
        self.btnSearch.setIcon(QIcon(os.path.join(pluginPath, "icons", "search.svg")))
        self.btnSearch.setStyleSheet("QToolButton { padding: 0px; }")
        self.btnSearch.setCursor(Qt.ArrowCursor)
        self.btnSearch.clicked.connect(self.buttonClicked.emit)

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        buttonSize = self.btnSearch.sizeHint()

        self.setStyleSheet("QLineEdit {{padding-right: {}px; }}".format(buttonSize.width() + frameWidth + 1))
        self.setMinimumSize(max(self.minimumSizeHint().width(), buttonSize.width() + frameWidth * 2 + 2),
                            max(self.minimumSizeHint().height(), buttonSize.height() + frameWidth * 2 + 2))

    def resizeEvent(self, event):
        buttonSize = self.btnSearch.sizeHint()
        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.btnSearch.move(self.rect().right() - frameWidth - buttonSize.width(),
                            (self.rect().bottom() - buttonSize.height() + 1) / 2)

        super(ButtonLineEdit, self).resizeEvent(event)
Exemplo n.º 2
0
class IconLineEdit(QLineEdit):
    def __init__(self, parent=None):
        QLineEdit.__init__(self, parent)

        self.btnIcon = QToolButton(self)
        self.btnIcon.setEnabled(False)
        self.btnIcon.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.setStyleSheet("QLineEdit {{ padding-left: {}px; }} ".format(
            self.btnIcon.sizeHint().width() + frameWidth + 1))
        msz = self.minimumSizeHint()
        self.setMinimumSize(
            max(msz.width(),
                self.btnIcon.sizeHint().height() + frameWidth * 2 + 2),
            max(msz.height(),
                self.btnIcon.sizeHint().height() + frameWidth * 2 + 2))

    def resizeEvent(self, event):
        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)

        sz = self.btnIcon.sizeHint()
        self.btnIcon.move(frameWidth + 1,
                          (self.rect().bottom() + 1 - sz.height()) / 2)

    def setIcon(self, icon):
        self.btnIcon.setIcon(icon)
Exemplo n.º 3
0
class PasswordLineEdit(QLineEdit):
    def __init__(self, parent=None):
        QLineEdit.__init__(self, parent)

        self.setPlaceholderText(self.tr("Password"))
        self.setEchoMode(QLineEdit.Password)

        self.btnIcon = QToolButton(self)
        self.btnIcon.setIcon(QIcon(os.path.join(iconsPath, "lock.svg")))
        self.btnIcon.setEnabled(False)
        self.btnIcon.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")

        self.btnToggle = QToolButton(self)
        self.btnToggle.setIcon(QIcon(os.path.join(iconsPath, "eye-slash.svg")))
        self.btnToggle.setCheckable(True)
        self.btnToggle.setToolTip(self.tr("Toggle password visibility"))
        self.btnToggle.setCursor(Qt.ArrowCursor)
        self.btnToggle.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")

        self.btnToggle.toggled.connect(self.togglePassword)

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.setStyleSheet(
            "QLineEdit {{ padding-right: {}px; padding-left: {}px }} ".format(
                self.btnToggle.sizeHint().width() + frameWidth + 1,
                self.btnIcon.sizeHint().width() + frameWidth + 1))
        msz = self.minimumSizeHint()
        self.setMinimumSize(
            max(msz.width(),
                self.btnToggle.sizeHint().height() + frameWidth * 2 + 2),
            max(msz.height(),
                self.btnToggle.sizeHint().height() + frameWidth * 2 + 2))

    def resizeEvent(self, event):
        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)

        sz = self.btnIcon.sizeHint()
        self.btnIcon.move(frameWidth + 1,
                          (self.rect().bottom() + 1 - sz.height()) / 2)

        sz = self.btnToggle.sizeHint()
        self.btnToggle.move(self.rect().right() - frameWidth - sz.width(),
                            (self.rect().bottom() + 1 - sz.height()) / 2)

    def togglePassword(self, toggled):
        if toggled:
            self.setEchoMode(QLineEdit.Normal)
            self.btnToggle.setIcon(QIcon(os.path.join(iconsPath, "eye.svg")))
        else:
            self.setEchoMode(QLineEdit.Password)
            self.btnToggle.setIcon(
                QIcon(os.path.join(iconsPath, "eye-slash.svg")))