Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:57:06+00:00 2026-05-31T15:57:06+00:00

I use a QPainter to draw my widget with this code: QPen pen(Qt::black, 0.6,

  • 0

I use a QPainter to draw my widget with this code:

QPen pen(Qt::black, 0.6, Qt::SolidLine);
QPainter painter(this);
painter.setPen(pen);

// vertical 
painter.drawLine(startX,0,startX,50);
painter.drawLine((startX += grid),0,startX,50);
painter.drawLine((startX += grid),0,startX,50);
painter.drawLine((startX += grid),0,startX,50);
painter.drawLine((startX += grid),0,startX,50);
painter.drawLine((startX += grid),0,startX,50);

// horizontal 
pen.setWidth(0.7);
painter.setPen(pen);
painter.drawLine(0,grid*2,70,grid*2);
painter.drawLine(0,grid*4,70,grid*4);
painter.drawLine(0,grid*6,70,grid*6);
painter.drawLine(0,grid*8,70,grid*8);

When I add this item into a QGraphicsScene, the width of the lines sometimes look different from each other, especially when I zoom in. Can anyone explain why this is happening and what can be done to fix it?

This screen shot demonstrates the problem:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:57:07+00:00Added an answer on May 31, 2026 at 3:57 pm

    This is a side effect of floating point rounding and scene interpolation/rendering. At most zoom levels, there will not be a perfect one-to-one match from scene pixels to view pixels. This is especially true for fractional pen widths. You can make things look a bit smoother by turning on anti-aliasing in your QGraphicsView:

    ...
    view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    ....
    

    There are other rendering hints that can be passed in as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've figured out how to use QPainter to draw rectangles. Now I want to
How to use QPainter and QTimer to draw a real time sinusoid like sinus(
QGraphicsItem::paint has the following signature: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) When
use this website a lot but first time posting. My program creates a number
I use QPainter to drawText on QPrinter; however, there is a problem. I hope
I use QPainter::setRenderHint(QPainter::Antialiasing, true) to tell Qt that I want it to antialias any
I've had soooo much trouble getting this code to work properly!!!! It runs fine
I am attempting to use PyQT to position and display a custom widget. Thus
Use trap to capture signals like this: i=-1;while((++i<33)); do trap echo $i >> log.txt
I am writing an info-screen program. I created a full-screen widget and draw contents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.