pyqt5 qprogressbar边界半径问题

发布于 2025-02-06 11:49:54 字数 1991 浏览 1 评论 0原文

我在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/>

I made a progress bar in PyQt5 designer with the following stylesheet:

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

but there seems to be a graphical glitch where the bar does not round and the text is misaligned.
enter image description here

is this a known issue?

A .ui file if needed, could be easily replicated by dragging a progress bar in designer and using the stylesheet above.

<?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/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2025-02-13 11:49:54

您必须在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 其他方法可以自定义进度栏示例。

You have to set the border radius on the QProgressBar chunk. I am not certain how it's done in .ui file but using qss it looks like this:

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

check out https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qprogressbar for other ways to customize the progress bar examples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文