1 Attachment(s)
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.
Attachment 11548
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)
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).
Re: How to create hexagonal shaped pushButton in pyqt4?
how can i make the corners of this hexagon rounded ?
Re: How to create hexagonal shaped pushButton in pyqt4?
Quote:
Originally Posted by
femy
how can i make the corners of this hexagon rounded ?
By opening rsz_imagetest.png in your favorite image editor?