簡體   English   中英

PyQt5 QProgressBar 邊界半徑問題

[英]PyQt5 QProgressBar border radius issue

我使用以下樣式表在 PyQt5 設計器中制作了一個進度條:

border: 2px solid black;
border-radius: 20px;

但似乎存在圖形故障,條形不圓且文本未對齊。 在此處輸入圖像描述

這是一個已知的問題?

如果需要,可以通過在設計器中拖動進度條並使用上面的樣式表輕松復制 .ui 文件。

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>289</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QProgressBar" name="progressBar">
    <property name="geometry">
     <rect>
      <x>90</x>
      <y>110</y>
      <width>201</width>
      <height>61</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">border: 2px solid black;
border-radius: 20px;</string>
    </property>
    <property name="value">
     <number>24</number>
    </property>
    <property name="textVisible">
     <bool>true</bool>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>26</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>

您必須在 QProgressBar 塊上設置邊框半徑。 我不確定它是如何在 .ui 文件中完成的,但使用 qss 它看起來像這樣:

QProgressBar {
  border: 2px solid black;
  border-radius: 20px;
  text-align: center;   
}
QProgressBar::chunk {
  border-radius: 5px; 
}

查看https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qprogressbar了解自定義進度條示例的其他方法。

暫無
暫無

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

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