qt5 - 如何避免带有 borderimage 的 QPushButton 的文本剪切

标签 qt5 styling qpushbutton qtwidgets

我正在设计一个带有 28px 边框图像的 QPushButton 样式(对于真正的圆角),如下所示:

#MyApp QPushButton
{
    margin:0;
    padding: 0;
    border:0;
    border-image: url(:/graphics/button_brand_up.png) 28 28 28 28 stretch stretch;
    border-top: 28px transparent;
    border-bottom: 28px transparent;
    border-right: 28px transparent;
    border-left: 28px transparent;
}

但是,当渲染按钮时,按钮上的文本标签似乎被剪切到边框图像的内部补丁。就我而言,这结果是灾难性的:

enter image description here

如何解决此问题,以便在按钮的整个表面(包括边框边缘)上呈现文本?

最佳答案

事实证明,这比最初预期的更简单、更直观。

解决方案是将按钮上的负填充设置为与边框图像半径相同,如下所示:

#MyApp QPushButton
{
    margin:0;
    padding: -28px; /* THIS SOLVED IT */
    border:0;
    border-image: url(:/graphics/button_brand_up.png) 28 28 28 28 stretch stretch;
    border-top: 28px transparent;
    border-bottom: 28px transparent;
    border-right: 28px transparent;
    border-left: 28px transparent;
}

现在按钮看起来正确了:

enter image description here

关于qt5 - 如何避免带有 borderimage 的 QPushButton 的文本剪切,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24590564/

相关文章:

qt - 我如何支持每个 QTableView 单元格两个单独的可双击值?

html - 这些列表中的样式有什么问题 (HTML)

react-native - React Native按比例缩放方形图像

c++ - 使用 Qt5 在 Windows 上获取 HWND(来自 WId)

c++ - QML TableView + QAbstractTableModel - 如何从 QML 编辑模型数据?

html - 需要实现特定的CSS Layout

python - 使用 Pyqt5 为按钮添加功能

python - 如何让QPushButton一点击就可编辑文本?

c++ - 如何在 QPushButton 中自动调整文本?

c++ - 在同一 UI 中使用 N.2 QGraphicsView 时 QWheelEvent 不起作用