我有两个小部件,它们都具有相同颜色的深色背景。这些小部件位于一个
如果我不使用抗锯齿,一切都看起来正常——两个小部件的背景合并为一个连续的黑暗区域。通过
有没有可能以某种方式摆脱这条线?完全关闭抗锯齿不是选项,因为这两个小部件都有圆角,没有抗锯齿看起来很糟糕。
编辑:
我现在列出了一个“最小”示例:
QGridLayout
中的相邻单元格中,该单元格在所有边缘上均具有ContentsMargins
和0间距。我使用自定义的QStyle
派生类进行绘制。如果我不使用抗锯齿,一切都看起来正常——两个小部件的背景合并为一个连续的黑暗区域。通过
painter->setRenderHint(QPainter::Antialiasing, true);
打开抗锯齿会在这两个小部件之间留下一条细(1像素)的白线。有没有可能以某种方式摆脱这条线?完全关闭抗锯齿不是选项,因为这两个小部件都有圆角,没有抗锯齿看起来很糟糕。
编辑:
我现在列出了一个“最小”示例:
#include <QApplication>
#include <QWidget>
#include <QGridLayout>
#include <QPainter>
class foo : public QWidget
{
protected:
void paintEvent(QPaintEvent *) {
QPainter painter(this);
int x1, y1, x2, y2;
int radius = 20;
int diam = 2 * radius;
rect().getCoords(&x1, &y1, &x2, &y2);
QPainterPath path; // This will be a rounded rectangle.
path.moveTo(x1 + radius, y2);
path.lineTo(x2 - radius, y2);
path.arcTo(x2 - diam, y2 - diam, diam, diam, 270.0, 90.0);
path.lineTo(x2, y1 + radius);
path.arcTo(x2 - diam, y1, diam, diam, 0.0, 90.0);
path.lineTo(x1 + radius, y1);
path.arcTo (x1, y1, diam, diam, 90.0, 90.0);
path.lineTo(x1, y2 - radius);
path.arcTo (x1, y2 - diam, diam, diam, 180.0, 90.0);
path.closeSubpath();
painter.setPen(Qt::gray);
// Comment out the following line and the rounded rectangles
// will not have a thin boundary of background color between them
painter.setRenderHint(QPainter::Antialiasing, true);
painter.fillPath(path, Qt::gray);
painter.drawPath(path);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGridLayout *l = new QGridLayout;
l->setContentsMargins(0,0,0,0);
l->setSpacing(0);
foo *c1 = new foo;
foo *c2 = new foo;
l->addWidget(c1, 0, 0);
l->addWidget(c2, 0, 1);
QWidget *w = new QWidget;
w->setMinimumSize(500,250);
w->setLayout(l);
w->show();
return a.exec();
}
我正在使用Qt 4.7.3在Ubuntu上工作。