簡體   English   中英

PyQt4:如何使Icon比QPushButton大? (像素圖按鈕)

[英]PyQt4: How to make Icon bigger than QPushButton? (Pixmap Buttons)

我正在努力制作一個Pixmap按鈕,因為沒有其他選擇(我知道),我嘗試過使用QIcon。

我想要作為按鈕的圖片不是完全正方形,我只想顯示像素圖,但是它仍然具有按鈕功能(信號連接到插槽等)。

當我嘗試使Icon的大小等於button時,Icon會上升,根本不適合按鈕,而button將顯示在icon之外。


所以問題是:

如何使圖標大於QPushButton? 因此只會顯示圖標,並且仍然具有圖標功能。

如果這超出了Icon的邊框,那么是否還有其他制作Pixmap按鈕的方法?

您可以像這樣使用background-image屬性簡單地使用css實現此目的,並將邊框設置為0

btn.setStyleSheet("background-image: url('image.jpg'); border: none;")

我使用PySide。 也許代碼是相似的

btn = QPushButton('')
btn.setIcon(QPixmap(image path))
# adjust width and height to fit the size of button.
btn.setIconSize(QSize(width, height))   
# set zero border.
btn.setStyleSheet('QPushButton{border: 0px solid;}')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM