Results 1 to 4 of 4

Thread: How to create hexagonal shaped pushButton in pyqt4?

  1. #1
    Join Date
    Dec 2015
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Unix/X11

    Default How to create hexagonal shaped pushButton in pyqt4?

    Currently i am using border-image to get the shape.I want to change color of hexagon dynamically. if i try to change the color of hexagon using background-color, only the square back-ground color is changing.


    img.png


    class ExampleApp(QtGui.QMainWindow):
    def __init__(self):
    super(self.__class__, self).__init__()
    self.myFunction()

    def myFunction(self):
    self.newWindow = design_3.Ui_MainWindow()
    self.newWindow.setupUi(self);
    self.newWindow.campusNameLabel.setStyleSheet("QLab el { color : white; }");
    self.newWindow.campusNameLabel.setText("Label 1")


    gridLayout = QtGui.QGridLayout()
    gridLayout.setSpacing(5)
    gridLayout.setRowStretch(1,1)
    gridLayout.setVerticalSpacing(20)


    alertBtn = QtGui.QPushButton("myBtn",self)
    alertBtn.setAutoFillBackground(True)
    alertBtn.setFlat(True)
    alertBtn.setSizePolicy(QtGui.QSizePolicy.Preferred , QtGui.QSizePolicy.Preferred)
    alertBtn.setMaximumWidth(150)
    alertBtn.setMaximumHeight(150)
    alertBtn.setMinimumWidth(150)
    alertBtn.setMinimumHeight(150)


    alertBtn.setStyleSheet("border-image: url(rsz_imagetest.png);background-color:black;")
    gridLayout.addWidget(alertBtn,0,0)
    self.newWindow.verticalLayout_2.addLayout(gridLayo ut)

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to create hexagonal shaped pushButton in pyqt4?

    The colour comes from your image. If you want to change the colour you will need to change the image.

    Another approach would be to subclass QPushbutton and provide it a paint() function that draws the button with QPainter (using a member variable to hold the desired button colour).

  3. The following user says thank you to ChrisW67 for this useful post:

    femy (2nd December 2015)

  4. #3
    Join Date
    Dec 2015
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Unix/X11

    Default Re: How to create hexagonal shaped pushButton in pyqt4?

    how can i make the corners of this hexagon rounded ?

  5. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to create hexagonal shaped pushButton in pyqt4?

    Quote Originally Posted by femy View Post
    how can i make the corners of this hexagon rounded ?
    By opening rsz_imagetest.png in your favorite image editor?

Similar Threads

  1. pyQt4 QGraphicsScene moving pushButton
    By rico46 in forum Newbie
    Replies: 0
    Last Post: 15th July 2015, 22:23
  2. Replies: 9
    Last Post: 2nd September 2013, 14:03
  3. Custom Shaped QPushButton
    By frknml in forum Qt Programming
    Replies: 1
    Last Post: 6th December 2010, 15:28
  4. PyQt4: Create simple GUI for python program
    By Norchina in forum Newbie
    Replies: 0
    Last Post: 11th June 2010, 15:50
  5. odd shaped buttons
    By jimiq in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2009, 20:50

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.