Skip to main content

PyQt button which supports svg icon (not a fake low quality svg icon)

Project description

pyqt-svg-button

PyQt button which supports svg icon

Qt's setIcon of button widget doesn't help that much in terms of setting SVG image as an icon. It's just another good old fashioned pixmap icon.

So i overrided the method to set SVG icon with the power of CSS.

By the way, parent class of this is QPushButton. I will update QToolButton of this when i'm ready to do so.

(the repo/package name has changed on 2022/05/18 from pyqt-svg-icon-pushbutton)

Requirements

  • PyQt5 >= 5.8

Setup

python -m pip install pyqt-svg-button

Usage

  • SvgButton(base_widget: QWidget = None) - Constructor. Base widget is the widget that the button's background color based of when button get hovered/pressed by mouse cursor. If value is default(None), background color of button which is getting hovered/pressed will set to #DDDDDD, #FFFFFF.

  • setIcon(icon: str) - set the icon. Icon should be a SVG file's name. This is overriding method.

  • setPadding(padding: int) - set the button's padding.

  • setBorderRadius(border_radius: int)

  • setBackground(background=None) - you can give background argument's value either 'transparent' or 6-digits or 3-digits hex color string or color's name like 'red', 'green'. As you see, default is set to None. If you set the value as default, background will automatically be set.

  • setAsCircle() - set button's shape as circle.

Included Packages

Example

Code Sample

from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout



from pyqt_svg_button.svgButton import SvgButton





class SvgButtonExample(QWidget):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        newButton = SvgButton()

        newButton.setIcon('new.svg')



        openButton = SvgButton()

        openButton.setIcon('open.svg')



        saveButton = SvgButton()

        saveButton.setIcon('save.svg')



        lay = QHBoxLayout()

        lay.addWidget(newButton)

        lay.addWidget(openButton)

        lay.addWidget(saveButton)



        self.setLayout(lay)





if __name__ == "__main__":

    import sys



    app = QApplication(sys.argv)

    ex = SvgButtonExample()

    ex.show()

    sys.exit(app.exec_())

Result

https://user-images.githubusercontent.com/55078043/153802219-ae019e5b-f603-4aad-93ce-035d33edd9a8.mp4

Sorry for the video quality.

image

Image quality is not perfect, but much better than video. Image above is slightly bigger than actual size.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqt-svg-button-0.0.20.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyqt_svg_button-0.0.20-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pyqt-svg-button-0.0.20.tar.gz.

File metadata

  • Download URL: pyqt-svg-button-0.0.20.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 CPython/3.7.6

File hashes

Hashes for pyqt-svg-button-0.0.20.tar.gz
Algorithm Hash digest
SHA256 ff7fda58e37ff326b5e685c1240ddca11db88dbf789b9c2b012eda36bcdacd1e
MD5 30d3c597f0bf5c465b7515d9335a9f7f
BLAKE2b-256 edce3ba1453855e23e350e2f9f0d33ee6ec0f683ee95e425d2e42bedbc5b2271

See more details on using hashes here.

File details

Details for the file pyqt_svg_button-0.0.20-py3-none-any.whl.

File metadata

File hashes

Hashes for pyqt_svg_button-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 c4ecbcc2ed2136c99d0c1b73ec9ab48b0c0bc6ca4ac77dd21d8d6abe97a3814e
MD5 9854e2456b627f05aaf30fb972231c73
BLAKE2b-256 5c7e2322dd174ef04ba79aeb5d21627ab00e4ebc0372007ba60074119462fb1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page