【问题标题】:Undesirable black border on my rect when i draw it with QPainter.drawRect()当我用 QPainter.drawRect() 绘制矩形时,矩形上出现不受欢迎的黑色边框
【发布时间】:2019-09-13 13:51:46
【问题描述】:

当我使用 drawRect() 时,我的矩形顶部有一条不受欢迎的一两个像素的黑线。 所以我的矩形没有完全填满我的小部件。

我的代码:

QPainter Painter(this);

QString TmpColor;

int R, G, B, A;

TmpColor = c_LabColor;

R = TmpColor.left(TmpColor.indexOf(',')).toInt();
TmpColor.remove(0, TmpColor.indexOf(',') + 1);
G = TmpColor.left(TmpColor.indexOf(',')).toInt();
TmpColor.remove(0, TmpColor.indexOf(',') + 1);
B = TmpColor.left(TmpColor.indexOf(',')).toInt();
TmpColor.remove(0, TmpColor.indexOf(',') + 1);
A = TmpColor.left(TmpColor.indexOf(',')).toInt();

Painter.setBrush(QBrush(QColor(R,G,B,A)));
Painter.drawRect(this->rect());

感谢您的建议。

【问题讨论】:

    标签: qt border drawrect qpainter


    【解决方案1】:

    QPainter::drawRect 使用当前笔绘制矩形轮廓,并使用当前笔填充矩形。由于您没有明确设置笔,它将是默认值,可能是黑色和 1 像素宽。因此是边界。

    如果您只想完全填充小部件矩形,则只需使用 QPainter::fillRect 重载之一...

    Painter.fillRect(rect(), QBrush(QColor(R,G,B,A)));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      相关资源
      最近更新 更多