我还没有找到如何使QMenu中的图标变大。我试图定义一个样式表,其中图标的大小被放大了。但它不起作用。这是我的代码:
menuStyleSheet = ("""
QMenu {
font-size: 18px;
color: black;
border: 2px solid black;
left: 20px;
background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #ffffff);
}
QMenu::item {
padding: 2px 20px 2px 30px;
border: 1px solid transparent; /* reserve space for selection border */
spacing: 20px;
height: 60px;
}
QMenu::icon {
padding-left: 20px;
width: 50px; /* <- unfortunately, doesn't work */
height: 50px; /* <- unfortunately, doesn't work */
}
""")
#####################################################
# THE PYQT APPLICATION #
#####################################################
class GMainWindow(QMainWindow):
def __init__(self, title):
super(GMainWindow, self).__init__()
...
def setCustomMenuBar(self):
myMenuBar = self.menuBar()
global menuStyleSheet
myMenuBar.setStyleSheet(menuStyleSheet)
# Now add Menus and QActions to myMenuBar..
此代码的结果如下:
我知道有一个关于类似主题的StAdppOver问题,但是它假设一个在C++中对Qt应用程序进行编码。所以情况就不同了。以下是链接:How to make Qt icon (in menu bar and tool bar) larger?
非常感谢您的帮助:-)
编辑:
以下是关于我的机器的一些细节:
经过长时间的寻找,我终于找到了解决办法。 只需复制粘贴下面的代码,并将其粘贴到
*.py
文件中。当然,您应该用本地计算机上的有效路径替换图标的路径。只需提供一个完整的路径(“C:\..”),以确保Qt找到图标绘图。在您将看到这样一个窗口,其中有一个巨大的图标:
那我是怎么解决的呢?显然,您不能用通常的方式增加QMenu项的图标大小—在样式表中定义大小。唯一的方法是提供一个新的
QStyle
,最好是从现有的QStyle
派生出来的。我找到了如何在C++中实现这方面的信息(见http://www.qtcentre.org/threads/21187-QMenu-always-displays-icons-aty-16x16-px),但没有对Pyqt的解释。 经过长时间的尝试和错误,我终于成功了:-)显然,更多的人在这种情况下挣扎:http://www.qtcentre.org/threads/61860-QMenu-Icon-Scale-in-PyQt
相关问题 更多 >
编程相关推荐