Skip to main content

pyqt-svg-icon-pushbutton

PyQt QPushButton which user can set svg icon(not a low quality).

I have to say that setIcon of QPushButton doensn't help that much in terms of setting SVG image as an icon. It's just another good old fashioned pixmap icon.

So i overrides the setIcon mtehod to set SVG icon with the power of CSS.

Requirements

  • PyQt5 >= 5.8

Setup

python -m pip install pyqt-svg-icon-pushbutton

Usage

  • SvgIconPushButton(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_icon_pushbutton.svgIconPushButton import SvgIconPushButton





class SvgIconPushButtonExample(QWidget):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        newButton = SvgIconPushButton()

        newButton.setIcon('new.svg')



        openButton = SvgIconPushButton()

        openButton.setIcon('open.svg')



        saveButton = SvgIconPushButton()

        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 = SvgIconPushButtonExample()

    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. Above image is slightly bigger than actual size.

I wish i know how to resize the video and image which are dropped on the README.md.

Metadata

Release files for pyqt-svg-icon-pushbutton 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyqt-svg-icon-pushbutton 0.0.15
File Size Uploaded
pyqt-svg-icon-pushbutton-0.0.15.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyqt-svg-icon-pushbutton 0.0.15
File Interpreter ABI Platform
pyqt_svg_icon_pushbutton-0.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / pyqt-svg-icon-pushbutton-0.0.15.tar.gz

Download URL pyqt-svg-icon-pushbutton-0.0.15.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b38657a86563a11dc76dba2023f8d213e6f522e082bf9052c63e98d047038995
BLAKE2b-256 checksum
How to use checksums
6bdc002af5102b4c5d01d20ec69b74c4f2f44ee11e23676f46bbf0e79ad6b5a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 CPython/3.7.6

Release files / pyqt_svg_icon_pushbutton-0.0.15-py3-none-any.whl

Download URL pyqt_svg_icon_pushbutton-0.0.15-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f9101524c84957d86bf8a5d2b10d2049a91c9ba6204beadd238c06e2de08272
BLAKE2b-256 checksum
How to use checksums
78126a03497d58a0447da411ebc47875352358d510b40805f9c8f7d52e21a440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.0.15 This release

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page