in Education by
I need to render a vector-only SVG without antialiasing in Qt; specifically, I don't want the resulting image to contain any color that was not exactly as specified in the source file. When loading an SVG in a QImage, Qt by default uses antialiasing; even using explicitly QSvgRenderer::render, the QPainter::Antialiasing render hint is ignored. This turns out to be obvious, as QSVGTinyDocument::draw, which seems to be the one who actually starts the drawing, is forcing it set: //sets default style on the painter //### not the most optimal way mapSourceToTarget(p, bounds); QPen pen(Qt::NoBrush, 1, Qt::SolidLine, Qt::FlatCap, Qt::SvgMiterJoin); pen.setMiterLimit(4); p->setPen(pen); p->setBrush(Qt::black); p->setRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::SmoothPixmapTransform); To circumvent this I tried to create a custom QPaintEngine wrapping the default one (and then subclass even QImage to return the wrapper QPaintEngine in the paintEngine() virtual method), but I couldn't find any clean way to intercept and alter the render hint on the way to the actual QPaintEngine. The QPaintEngine::update() method, which seems to be the way through which a QPaintEngine receives the flags, receives a reference to a QPaintEngineState, which is a horrible kludge that provides only getters, which in turn aren't virtual, so you cannot provide your implementation; internally just assumes it's actually operating an instance of an internal subclass (QPainterState) by brutally casting the this pointer and accessing its fields. Besides, even just providing a just-forwarding QPaintEngine resulted in segfaults inside the bowels of QPainter code, so I quickly desisted. Long story short: is there a way to forcibly disable/intercept and ignore/... the QPainter::Antialiasing render hint on a QPainter? (the QT_NO_ANTIALIASING environment variable doesn't count, as it is enabled only in builds without QT_NO_DEBUG); more in general, how can I render an SVG to a QImage without antialising? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The only solution I can think of is to implement your own SVG renderer. This is trivial using nanosvg, yet few people decide to do this. Also, like almost every other parser out there, nanosvg does not support every SVG feature (like filters, ...). Anyway, here's an example. You will have complete control, whether you want (anti)aliasing or not.

Related questions

0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    This is a long shot but, having come across a constrain in a form of a qt's signals, slots being ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    This is a long shot but, having come across a constrain in a form of a qt's signals, slots being ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I have a QGraphicsItem element (subclassesed from QGraphicsItem) that has as child a QGraphicsTextItem. The problem ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    A programmer builds a _________ to avoid repeating the same task or reduce complexity. (a) Function (b) Package ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Can you use SVG tags directly in HTML5 without any plugin? A - true B - false...
asked Dec 2, 2020 in Technology by JackTerrance
0 votes
    I have a function value(x) which is overloaded for many types such that: double value(double x) { return x; } double ... [-Wreturn-local-addr] in the following code: Matrix33 m; m...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    The only environment without a parent is the ________ environment. (a) full (b) half (c) null (d) empty ... Debugging of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am trying to use qt creator and python to generate flowcharts with values. I want to save the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How to concatenate a std::string and an int (24 answers) Closed 5 years ago. int i = 4; string text = "Player "; cout...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I have a bunch of vector classes. I have a 2D point vec2_t, a 3D point vec3_t and a 4D point ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have a bunch of vector classes. I have a 2D point vec2_t, a 3D point vec3_t and a 4D point ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    How will you check if an element is present in a vector? (a) Match() (b) Dismatch() (c) Mismatch() ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I was wondering if there is a good way to hook into the Application_Start of a SharePoint 2007 site when ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I would like to use ShellExecute in my C++ program to force the opening of a tiff image with ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...