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 and SvgAbstractButton. (Multiple inheritance)

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

Default background color of this is transparent.

If you want to use svg supporting QToolButton instead of QPushButton, use pyqt-svg-toolbutton.

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'. If you don't give any arguments(None), background will automatically be set based on base widget's color if you give base widget argument to SvgButton constructor.

  • 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.26.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

pyqt_svg_button-0.0.26-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyqt-svg-button-0.0.26.tar.gz
  • Upload date:
  • Size: 3.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.26.tar.gz
Algorithm Hash digest
SHA256 30d426b53b5d182866f07dd6ba3bfc32f70e154251058ccebb9c5c40df319f28
MD5 d1a40acf5c32c51d9c08096aacaf7518
BLAKE2b-256 363624571cf5faf43ac10b6115575fc6d53629c7e71a553d343c4a6506f0f575

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqt_svg_button-0.0.26-py3-none-any.whl
Algorithm Hash digest
SHA256 a9fe0278865ae3f8986e71685f3b0e1460a60266a88c0c7caf53d4dcb026f69a
MD5 9d150aac1327dc9c2316a774c169e580
BLAKE2b-256 c8740deb858394ac4dc62ab057098ae312feb335db9f7f228fdc2e25a995f24c

See more details on using hashes here.

Supported by

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