我想在原始图像坐标系中显示带有线和多边形的缩放图像,无论显示缩放如何,其中像素始终为 1x1 正方形。例如,我想显示一条从像素中心 (0, 0) 到像素中心 (9, 9) 的细线段,但下面的代码片段会生成一条粗线,因为比例太高了:
int main(int argc, char *argv[])
{
const int scale = 44;
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsView view(&scene);
QImage image("test.bmp");
auto line = new QGraphicsLineItem (0.5, 0.5, 9.5, 9.5);
line->setPen(QPen(Qt::blue));
scene.addPixmap(QPixmap::fromImage(image));
scene.addItem(line);
view.scale(scale, scale);
view.show();
return a.exec();
}
我怎样才能使这条线变细,使其在 将比例应用于宽度之前具有子像素厚度,从而使最终厚度小于 scale< 的值
?
这可以通过使用重新缩放的坐标 (scale*0.5, scale*0.5, scale*9.5, scale*9.5) 来实现,但我想避免这种情况。
最佳答案
看看void QPen::setWidth(int width)和 void QPen::setWidthF(qreal width) .
QPen pen(Qt::blue);
pen.setWidth(0);
line->setPen(pen);
关于c++ - 如何在 Qt 中缩放具有子像素宽度的线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32512002/