简体   繁体   English

如何更改 PyQt5 中的滚动条箭头键?

[英]How to change the Scrollbars Arrow Keys in PyQt5?

Using the following code to set the style for vertical Qscrollbar.使用以下代码设置垂直 Qscrollbar 的样式。 It gives the appearance/result as attached photo.它给出了附加照片的外观/结果。 I want to change the up and down arrow from Square to the actual up arrow ( triangle) on top and the down arrow at the bottom(inverse triangle).我想将上下箭头从 Square 更改为顶部的实际向上箭头(三角形)和底部的向下箭头(倒三角形)。 How to obtain it?如何获得?

在此处输入图片说明

   QScrollBar:vertical {
   background: rgb(220,220,220);
   width: 15px;
   margin: 22px 0 22px 0; }

   QScrollBar::handle:vertical {
   background: rgb(169,169,169);
   min-height: 10px; }
   
   QScrollBar::add-line:vertical {
   border: 0px solid grey;
   background: rgb(220,220,220);
   height: 20px;
   subcontrol-position: bottom;
   subcontrol-origin: margin; }

   QScrollBar::sub-line:vertical {
   border: 0px solid red;
   background: rgb(220,220,220);
   height: 20px;
   subcontrol-position: top;
   subcontrol-origin: margin;}
   
   QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
   border: 0px solid red;
   display: ᐃ
   width: 5px;
   height: 5px;
   background:black;}

You must use images to get arrow icons.您必须使用图像来获取箭头图标。

QScrollBar::right-arrow,
QScrollBar::left-arrow,
QScrollBar::up-arrow,
QScrollBar::down-arrow {
    width: 12px;
    height: 12px;
    background: black;
}

QScrollBar::right-arrow {
    image: url("://icons/theme-dark/caret_right.svg");
}
QScrollBar::left-arrow {
    image: url("://icons/theme-dark/caret_left.svg");
}
QScrollBar::up-arrow {
    image: url("://icons/theme-dark/caret_up.svg");
}
QScrollBar::down-arrow {
    image: url("://icons/theme-dark/caret_down.svg");
}

The images can be anything, in any format Qt supports (png, jpg, gif, etc).图像可以是任何东西,Qt 支持的任何格式(png、jpg、gif 等)。 The above URL syntax uses images embedded in an included Qt resource file (but they could also be file:// URLs, or actual network requests (http/s, etc)).上面的 URL 语法使用嵌入在包含的 Qt 资源文件中的图像(但它们也可以是file:// URL,或实际的网络请求(http/s 等))。

You do not need the :vertical or :horizontal qualifiers (the elements are already "directional").您不需要:vertical:horizontal限定符(元素已经是“定向的”)。 Also the way you're using display is incorrect, and besides Qt doesn't support it anyway (nor content which is I think what you meant).此外,您使用display方式不正确,而且 Qt 无论如何都不支持它(我认为您的意思也不支持content )。

In addition to manually supplying images for arrows, you could try different window styles.除了手动为箭头提供图像外,您还可以尝试不同的窗口样式。 If you use Designer for your app, you can preview styles from Form...Preview In -> Style.如果您为您的应用程序使用 Designer,您可以从 Form...Preview In -> Style 预览样式。 It's hard to find in the docs, but if you look here , there are some styles.在文档中很难找到,但如果你看这里,有一些样式。

In your code you do it at the app level:在您的代码中,您在应用程序级别执行此操作:

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setStyle(QStyleFactory.create('fusion'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM