Giter Club home page Giter Club logo

pyqt-rounded-profile-image's Introduction

pyqt-rounded-profile-image

PyQt rounded profile image like Youtube, Google, etc.

Profile image is QLabel. QPixmap's setMask fucntion is being used to make the image rounded.

Requirements

  • PyQt5

Install

clone

  • git clone ~
  • python sample.py

as a package

  • python -m pip install pyqt-rounded-profile-image

Method Overview

  • setImage(filename: str) - Set the image file to the circle.

Example

Code Sample

import os.path

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QVBoxLayout, QFileDialog

from pyqt_rounded_profile_image import RoundedImage


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.__initUi()

    def __initUi(self):
        self.__label = RoundedImage()
        
        # maximum size has to be set
        # otherwise, it will expand, regardless of the size policy setting
        # half of the actual size is recommended
        self.__label.setMaximumSize(128, 128)

        btn = QPushButton('Select the Image')
        btn.clicked.connect(self.__update)

        lay = QVBoxLayout()
        lay.addWidget(self.__label)
        lay.addWidget(btn)
        lay.setAlignment(Qt.AlignCenter)
        self.setLayout(lay)
        
        # set the image file name you want (as an default image)
        self.__label.setImage('a.png')

    def __update(self):
        # os.path.expanduser indicates the "Document" folder
        filename = QFileDialog.getOpenFileName(self, 'Select the Image', os.path.expanduser('~'), 'Image Files (*.png *.jpg *.bmp)')
        if filename[0]:
            filename = filename[0]
            self.__label.setImage(filename)


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    w = Window()
    w.show()
    sys.exit(app.exec_())

Result

image

You can select the image file to show (*.png, *.jpg, *.bmp)

There are two images (both two are Laurie Holden) in the root directory for testing the feature.

TODO list

  • Default image or text
  • Popup window
  • Animation
  • Ensure that the edges are smoother, regardless of the size

pyqt-rounded-profile-image's People

Contributors

yjg30737 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

pomxark

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.