Qt antialiasing sets different pen widths





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a qt app which has a big QGraphicsView where I draw a grid.



This grid reacts on mouse clicks. Basically, if you click on some box -> the box is made red. And if you double click on it -> it goes back to its original state (its white).



This is the implementation of my QGraphicsView:



#include "mapview.h"

// Constructors

mapview::mapview()
{
setUpGui();
}

mapview::mapview(QWidget *parent) : QGraphicsView(parent)
{
setUpGui();
}

// GUI setup

void mapview::setUpGui()
{
scene = new QGraphicsScene(this);

this->setScene(scene);
this->setRenderHint(QPainter::Antialiasing);
// this->setRenderHint(QPainter::HighQualityAntialiasing);
}

// Events

void mapview::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
lastPoint = event->pos();
scribbling = true;
}
}

void mapview::mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) && scribbling)
{
drawWall(event->pos());
}
}

void mapview::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && scribbling)
{
drawWall(event->pos());
scribbling = false;
}
}

void mapview::mouseDoubleClickEvent(QMouseEvent *event)
{
removeWall(event->pos());
}

// Drawing methods

void mapview::drawGrid(const int box_count)
{
scene->clear();

auto x = 0.0;
auto y = 0.0;

this->margin = 20.0;

_width = this->width() - 2 * margin;
_height = this->height() - 2 * margin;

if (fabs(_width - _height) >= std::numeric_limits<double>::epsilon())
{
// qDebug() << "width (" << width << ") != height (" << height << ")";
return;
}

this->box_count = box_count;
this->box_size = _width / box_count;



// Horizontal
for (auto i = 0; i <= box_count; i++)
{
QGraphicsLineItem *line = new QGraphicsLineItem(x, y, x + _width, y);
QPen pen;
pen.setColor(Qt::black);
line->setPen(pen);
// scene->addLine(x, y, x + _width, y);
scene->addItem(line);
y += box_size;
}

y = 0.0;

// Vertical
for (auto i = 0; i <= box_count; i++)
{
scene->addLine(x, y, x, y + _height);
x += box_size;
}
}

void mapview::drawWall(const QPointF &endPoint)
{
auto x = endPoint.x() - margin;
auto y = endPoint.y() - margin;

x = static_cast<int>(x / box_size) * box_size;
y = static_cast<int>(y / box_size) * box_size;

QGraphicsRectItem* rect = new QGraphicsRectItem(x, y, this->box_size, this->box_size);
rect->setBrush(QBrush(Qt::red));
rect->setPen(QPen());
scene->addItem(rect);
}

void mapview::removeWall(const QPointF &point)
{
auto x = point.x() - margin;
auto y = point.y() - margin;

x = static_cast<int>(x / box_size) * box_size;
y = static_cast<int>(y / box_size) * box_size;

QGraphicsRectItem* rect = new QGraphicsRectItem(x, y, this->box_size, this->box_size);
rect->setBrush(QBrush(Qt::white));
rect->setPen(QPen());
scene->addItem(rect);
}


As you can see at the top, I set up antialiasing. The problem is, that when I set it up, it somehow changes the view of my drawing:



This is the view of an untouched grid:



enter image description here



Now for the box 1x1 (indexed from 0) I've clicked it (made it red) and then I double clicked it (so it got back to its original state). The problem is, as you can see, the border of this box is kinda thicker:



enter image description here



Funny thing is, that it's only thicker on this view. If I zoom it in, there's no difference between its border and the borders of other boxes. The other thing is, if I set Qt::HighQualityAntialiasing -> the border is the same, but then the zooming gets laggy, I guess it has to do more heavy computations or something like this.



So my question here would be: Is there a way, to make the antialiasing not change the thickness of the border? (I mean, I know it doesn't really change it, but you can definitely see a difference here)










share|improve this question























  • Definitely not. Even on my phone I see the bottom picture different. By saying 1x1 I mean from the top left corner

    – dabljues
    Jan 7 at 15:20











  • My fault, was looking at the wrong cell ;)

    – cbuchart
    Jan 7 at 15:21











  • Try using sub-pixel coordinates instead, like <0.5, 0.5> instead of <0, 0>

    – cbuchart
    Jan 7 at 15:23













  • Well, I actually fixed the problem by not redrawing the box in white but just removing the old one from the scene, but I didn't know if I should delete my question or not, as it may be helpful to other people having this issue.

    – dabljues
    Jan 7 at 19:38






  • 1





    If you solved your issue I'd recommend you to publish your solution as an answer and accept it (you'll have to wait 2 days to mark it as solved). In this way your contribution will be more useful. If possible, explain how did it affected you or why it solves the issue: other ones may have a similar problem and your arguments may help them better than the solution itself.

    – cbuchart
    Jan 8 at 7:47


















0















I have a qt app which has a big QGraphicsView where I draw a grid.



This grid reacts on mouse clicks. Basically, if you click on some box -> the box is made red. And if you double click on it -> it goes back to its original state (its white).



This is the implementation of my QGraphicsView:



#include "mapview.h"

// Constructors

mapview::mapview()
{
setUpGui();
}

mapview::mapview(QWidget *parent) : QGraphicsView(parent)
{
setUpGui();
}

// GUI setup

void mapview::setUpGui()
{
scene = new QGraphicsScene(this);

this->setScene(scene);
this->setRenderHint(QPainter::Antialiasing);
// this->setRenderHint(QPainter::HighQualityAntialiasing);
}

// Events

void mapview::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
lastPoint = event->pos();
scribbling = true;
}
}

void mapview::mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) && scribbling)
{
drawWall(event->pos());
}
}

void mapview::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && scribbling)
{
drawWall(event->pos());
scribbling = false;
}
}

void mapview::mouseDoubleClickEvent(QMouseEvent *event)
{
removeWall(event->pos());
}

// Drawing methods

void mapview::drawGrid(const int box_count)
{
scene->clear();

auto x = 0.0;
auto y = 0.0;

this->margin = 20.0;

_width = this->width() - 2 * margin;
_height = this->height() - 2 * margin;

if (fabs(_width - _height) >= std::numeric_limits<double>::epsilon())
{
// qDebug() << "width (" << width << ") != height (" << height << ")";
return;
}

this->box_count = box_count;
this->box_size = _width / box_count;



// Horizontal
for (auto i = 0; i <= box_count; i++)
{
QGraphicsLineItem *line = new QGraphicsLineItem(x, y, x + _width, y);
QPen pen;
pen.setColor(Qt::black);
line->setPen(pen);
// scene->addLine(x, y, x + _width, y);
scene->addItem(line);
y += box_size;
}

y = 0.0;

// Vertical
for (auto i = 0; i <= box_count; i++)
{
scene->addLine(x, y, x, y + _height);
x += box_size;
}
}

void mapview::drawWall(const QPointF &endPoint)
{
auto x = endPoint.x() - margin;
auto y = endPoint.y() - margin;

x = static_cast<int>(x / box_size) * box_size;
y = static_cast<int>(y / box_size) * box_size;

QGraphicsRectItem* rect = new QGraphicsRectItem(x, y, this->box_size, this->box_size);
rect->setBrush(QBrush(Qt::red));
rect->setPen(QPen());
scene->addItem(rect);
}

void mapview::removeWall(const QPointF &point)
{
auto x = point.x() - margin;
auto y = point.y() - margin;

x = static_cast<int>(x / box_size) * box_size;
y = static_cast<int>(y / box_size) * box_size;

QGraphicsRectItem* rect = new QGraphicsRectItem(x, y, this->box_size, this->box_size);
rect->setBrush(QBrush(Qt::white));
rect->setPen(QPen());
scene->addItem(rect);
}


As you can see at the top, I set up antialiasing. The problem is, that when I set it up, it somehow changes the view of my drawing:



This is the view of an untouched grid:



enter image description here



Now for the box 1x1 (indexed from 0) I've clicked it (made it red) and then I double clicked it (so it got back to its original state). The problem is, as you can see, the border of this box is kinda thicker:



enter image description here



Funny thing is, that it's only thicker on this view. If I zoom it in, there's no difference between its border and the borders of other boxes. The other thing is, if I set Qt::HighQualityAntialiasing -> the border is the same, but then the zooming gets laggy, I guess it has to do more heavy computations or something like this.



So my question here would be: Is there a way, to make the antialiasing not change the thickness of the border? (I mean, I know it doesn't really change it, but you can definitely see a difference here)










share|improve this question























  • Definitely not. Even on my phone I see the bottom picture different. By saying 1x1 I mean from the top left corner

    – dabljues
    Jan 7 at 15:20











  • My fault, was looking at the wrong cell ;)

    – cbuchart
    Jan 7 at 15:21











  • Try using sub-pixel coordinates instead, like <0.5, 0.5> instead of <0, 0>

    – cbuchart
    Jan 7 at 15:23













  • Well, I actually fixed the problem by not redrawing the box in white but just removing the old one from the scene, but I didn't know if I should delete my question or not, as it may be helpful to other people having this issue.

    – dabljues
    Jan 7 at 19:38






  • 1





    If you solved your issue I'd recommend you to publish your solution as an answer and accept it (you'll have to wait 2 days to mark it as solved). In this way your contribution will be more useful. If possible, explain how did it affected you or why it solves the issue: other ones may have a similar problem and your arguments may help them better than the solution itself.

    – cbuchart
    Jan 8 at 7:47














0












0








0








I have a qt app which has a big QGraphicsView where I draw a grid.



This grid reacts on mouse clicks. Basically, if you click on some box -> the box is made red. And if you double click on it -> it goes back to its original state (its white).



This is the implementation of my QGraphicsView:



#include "mapview.h"

// Constructors

mapview::mapview()
{
setUpGui();
}

mapview::mapview(QWidget *parent) : QGraphicsView(parent)
{
setUpGui();
}

// GUI setup

void mapview::setUpGui()
{
scene = new QGraphicsScene(this);

this->setScene(scene);
this->setRenderHint(QPainter::Antialiasing);
// this->setRenderHint(QPainter::HighQualityAntialiasing);
}

// Events

void mapview::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
lastPoint = event->pos();
scribbling = true;
}
}

void mapview::mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) && scribbling)
{
drawWall(event->pos());
}
}

void mapview::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && scribbling)
{
drawWall(event->pos());
scribbling = false;
}
}

void mapview::mouseDoubleClickEvent(QMouseEvent *event)
{
removeWall(event->pos());
}

// Drawing methods

void mapview::drawGrid(const int box_count)
{
scene->clear();

auto x = 0.0;
auto y = 0.0;

this->margin = 20.0;

_width = this->width() - 2 * margin;
_height = this->height() - 2 * margin;

if (fabs(_width - _height) >= std::numeric_limits<double>::epsilon())
{
// qDebug() << "width (" << width << ") != height (" << height << ")";
return;
}

this->box_count = box_count;
this->box_size = _width / box_count;



// Horizontal
for (auto i = 0; i <= box_count; i++)
{
QGraphicsLineItem *line = new QGraphicsLineItem(x, y, x + _width, y);
QPen pen;
pen.setColor(Qt::black);
line->setPen(pen);
// scene->addLine(x, y, x + _width, y);
scene->addItem(line);
y += box_size;
}

y = 0.0;

// Vertical
for (auto i = 0; i <= box_count; i++)
{
scene->addLine(x, y, x, y + _height);
x += box_size;
}
}

void mapview::drawWall(const QPointF &endPoint)
{
auto x = endPoint.x() - margin;
auto y = endPoint.y() - margin;

x = static_cast<int>(x / box_size) * box_size;
y = static_cast<int>(y / box_size) * box_size;

QGraphicsRectItem* rect = new QGraphicsRectItem(x, y, this->box_size, this->box_size);
rect->setBrush(QBrush(Qt::red));
rect->setPen(QPen());
scene->addItem(rect);
}

void mapview::removeWall(const QPointF &point)
{
auto x = point.x() - margin;
auto y = point.y() - margin;

x = static_cast<int>(x / box_size) * box_size;
y = static_cast<int>(y / box_size) * box_size;

QGraphicsRectItem* rect = new QGraphicsRectItem(x, y, this->box_size, this->box_size);
rect->setBrush(QBrush(Qt::white));
rect->setPen(QPen());
scene->addItem(rect);
}


As you can see at the top, I set up antialiasing. The problem is, that when I set it up, it somehow changes the view of my drawing:



This is the view of an untouched grid:



enter image description here



Now for the box 1x1 (indexed from 0) I've clicked it (made it red) and then I double clicked it (so it got back to its original state). The problem is, as you can see, the border of this box is kinda thicker:



enter image description here



Funny thing is, that it's only thicker on this view. If I zoom it in, there's no difference between its border and the borders of other boxes. The other thing is, if I set Qt::HighQualityAntialiasing -> the border is the same, but then the zooming gets laggy, I guess it has to do more heavy computations or something like this.



So my question here would be: Is there a way, to make the antialiasing not change the thickness of the border? (I mean, I know it doesn't really change it, but you can definitely see a difference here)










share|improve this question














I have a qt app which has a big QGraphicsView where I draw a grid.



This grid reacts on mouse clicks. Basically, if you click on some box -> the box is made red. And if you double click on it -> it goes back to its original state (its white).



This is the implementation of my QGraphicsView:



#include "mapview.h"

// Constructors

mapview::mapview()
{
setUpGui();
}

mapview::mapview(QWidget *parent) : QGraphicsView(parent)
{
setUpGui();
}

// GUI setup

void mapview::setUpGui()
{
scene = new QGraphicsScene(this);

this->setScene(scene);
this->setRenderHint(QPainter::Antialiasing);
// this->setRenderHint(QPainter::HighQualityAntialiasing);
}

// Events

void mapview::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
lastPoint = event->pos();
scribbling = true;
}
}

void mapview::mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) && scribbling)
{
drawWall(event->pos());
}
}

void mapview::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && scribbling)
{
drawWall(event->pos());
scribbling = false;
}
}

void mapview::mouseDoubleClickEvent(QMouseEvent *event)
{
removeWall(event->pos());
}

// Drawing methods

void mapview::drawGrid(const int box_count)
{
scene->clear();

auto x = 0.0;
auto y = 0.0;

this->margin = 20.0;

_width = this->width() - 2 * margin;
_height = this->height() - 2 * margin;

if (fabs(_width - _height) >= std::numeric_limits<double>::epsilon())
{
// qDebug() << "width (" << width << ") != height (" << height << ")";
return;
}

this->box_count = box_count;
this->box_size = _width / box_count;



// Horizontal
for (auto i = 0; i <= box_count; i++)
{
QGraphicsLineItem *line = new QGraphicsLineItem(x, y, x + _width, y);
QPen pen;
pen.setColor(Qt::black);
line->setPen(pen);
// scene->addLine(x, y, x + _width, y);
scene->addItem(line);
y += box_size;
}

y = 0.0;

// Vertical
for (auto i = 0; i <= box_count; i++)
{
scene->addLine(x, y, x, y + _height);
x += box_size;
}
}

void mapview::drawWall(const QPointF &endPoint)
{
auto x = endPoint.x() - margin;
auto y = endPoint.y() - margin;

x = static_cast<int>(x / box_size) * box_size;
y = static_cast<int>(y / box_size) * box_size;

QGraphicsRectItem* rect = new QGraphicsRectItem(x, y, this->box_size, this->box_size);
rect->setBrush(QBrush(Qt::red));
rect->setPen(QPen());
scene->addItem(rect);
}

void mapview::removeWall(const QPointF &point)
{
auto x = point.x() - margin;
auto y = point.y() - margin;

x = static_cast<int>(x / box_size) * box_size;
y = static_cast<int>(y / box_size) * box_size;

QGraphicsRectItem* rect = new QGraphicsRectItem(x, y, this->box_size, this->box_size);
rect->setBrush(QBrush(Qt::white));
rect->setPen(QPen());
scene->addItem(rect);
}


As you can see at the top, I set up antialiasing. The problem is, that when I set it up, it somehow changes the view of my drawing:



This is the view of an untouched grid:



enter image description here



Now for the box 1x1 (indexed from 0) I've clicked it (made it red) and then I double clicked it (so it got back to its original state). The problem is, as you can see, the border of this box is kinda thicker:



enter image description here



Funny thing is, that it's only thicker on this view. If I zoom it in, there's no difference between its border and the borders of other boxes. The other thing is, if I set Qt::HighQualityAntialiasing -> the border is the same, but then the zooming gets laggy, I guess it has to do more heavy computations or something like this.



So my question here would be: Is there a way, to make the antialiasing not change the thickness of the border? (I mean, I know it doesn't really change it, but you can definitely see a difference here)







c++ qt antialiasing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 4 at 18:45









dabljuesdabljues

3307




3307













  • Definitely not. Even on my phone I see the bottom picture different. By saying 1x1 I mean from the top left corner

    – dabljues
    Jan 7 at 15:20











  • My fault, was looking at the wrong cell ;)

    – cbuchart
    Jan 7 at 15:21











  • Try using sub-pixel coordinates instead, like <0.5, 0.5> instead of <0, 0>

    – cbuchart
    Jan 7 at 15:23













  • Well, I actually fixed the problem by not redrawing the box in white but just removing the old one from the scene, but I didn't know if I should delete my question or not, as it may be helpful to other people having this issue.

    – dabljues
    Jan 7 at 19:38






  • 1





    If you solved your issue I'd recommend you to publish your solution as an answer and accept it (you'll have to wait 2 days to mark it as solved). In this way your contribution will be more useful. If possible, explain how did it affected you or why it solves the issue: other ones may have a similar problem and your arguments may help them better than the solution itself.

    – cbuchart
    Jan 8 at 7:47



















  • Definitely not. Even on my phone I see the bottom picture different. By saying 1x1 I mean from the top left corner

    – dabljues
    Jan 7 at 15:20











  • My fault, was looking at the wrong cell ;)

    – cbuchart
    Jan 7 at 15:21











  • Try using sub-pixel coordinates instead, like <0.5, 0.5> instead of <0, 0>

    – cbuchart
    Jan 7 at 15:23













  • Well, I actually fixed the problem by not redrawing the box in white but just removing the old one from the scene, but I didn't know if I should delete my question or not, as it may be helpful to other people having this issue.

    – dabljues
    Jan 7 at 19:38






  • 1





    If you solved your issue I'd recommend you to publish your solution as an answer and accept it (you'll have to wait 2 days to mark it as solved). In this way your contribution will be more useful. If possible, explain how did it affected you or why it solves the issue: other ones may have a similar problem and your arguments may help them better than the solution itself.

    – cbuchart
    Jan 8 at 7:47

















Definitely not. Even on my phone I see the bottom picture different. By saying 1x1 I mean from the top left corner

– dabljues
Jan 7 at 15:20





Definitely not. Even on my phone I see the bottom picture different. By saying 1x1 I mean from the top left corner

– dabljues
Jan 7 at 15:20













My fault, was looking at the wrong cell ;)

– cbuchart
Jan 7 at 15:21





My fault, was looking at the wrong cell ;)

– cbuchart
Jan 7 at 15:21













Try using sub-pixel coordinates instead, like <0.5, 0.5> instead of <0, 0>

– cbuchart
Jan 7 at 15:23







Try using sub-pixel coordinates instead, like <0.5, 0.5> instead of <0, 0>

– cbuchart
Jan 7 at 15:23















Well, I actually fixed the problem by not redrawing the box in white but just removing the old one from the scene, but I didn't know if I should delete my question or not, as it may be helpful to other people having this issue.

– dabljues
Jan 7 at 19:38





Well, I actually fixed the problem by not redrawing the box in white but just removing the old one from the scene, but I didn't know if I should delete my question or not, as it may be helpful to other people having this issue.

– dabljues
Jan 7 at 19:38




1




1





If you solved your issue I'd recommend you to publish your solution as an answer and accept it (you'll have to wait 2 days to mark it as solved). In this way your contribution will be more useful. If possible, explain how did it affected you or why it solves the issue: other ones may have a similar problem and your arguments may help them better than the solution itself.

– cbuchart
Jan 8 at 7:47





If you solved your issue I'd recommend you to publish your solution as an answer and accept it (you'll have to wait 2 days to mark it as solved). In this way your contribution will be more useful. If possible, explain how did it affected you or why it solves the issue: other ones may have a similar problem and your arguments may help them better than the solution itself.

– cbuchart
Jan 8 at 7:47












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54044443%2fqt-antialiasing-sets-different-pen-widths%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54044443%2fqt-antialiasing-sets-different-pen-widths%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas