vladik
vladik

Reputation: 53

PyQt6: QPushButton icon/text has large margin

issue

        self.pbBuy.setMinimumSize(QtCore.QSize(143, 40))
        self.pbBuy.setMaximumSize(QtCore.QSize(16777215, 40))
        self.pbBuy.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.PointingHandCursor))
        self.pbBuy.setStyleSheet("QPushButton {\n"
    "    background: qlineargradient(spread:pad, x1:0.494, y1:0.00568182, x2:0.534, y2:1, stop:0 rgba(217, 217, 217, .8), stop:1 rgba(115, 115, 115, .8));\n"
    "    color: white;\n"
    "    font-size: 12px;\n"
    "    font-weight: 400;\n"
    "    font-family: \"Goldman\";\n"
    "    border-radius: 10px;\n"
    "    border: 0;    \n"
    "}\n"
    "\n"
    "QPushButton:hover {\n"
    "    background: qlineargradient(spread:pad, x1:0.494, y1:0.00568182, x2:0.534, y2:1, stop:0 rgba(237, 237, 237, .8), stop:1 rgba(135, 135, 135, .8));\n"
    "}\n"
    "\n"
    "QPushButton:pressed {\n"
    "    background: qlineargradient(spread:pad, x1:0.494, y1:0.00568182, x2:0.534, y2:1, stop:0 rgba(197, 197, 197, .8), stop:1 rgba(95, 95, 95, .8));\n"
    "}")
            icon1 = QtGui.QIcon()
            icon1.addPixmap(QtGui.QPixmap(":/images/images/authdlg_key.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
            self.pbBuy.setIcon(icon1)
            self.pbBuy.setIconSize(QtCore.QSize(18, 18))
            self.pbBuy.setAutoDefault(False)
            self.pbBuy.setObjectName("pbBuy")

I`m tried to:

  1. create a custom widget QPushButton and write a paintEvent, but no result.
  2. remove stylesheet of the button
  3. add icon in code
  4. add icon with QtDesigner

I just don`t know what to do with this problem..

PyQt6: 6.6.1

python: 3.12

Upvotes: 0

Views: 50

Answers (0)

Related Questions