Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsView: is selective antialiasing possible?
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView: is selective antialiasing possible?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JanLaloux
    wrote on last edited by SGaist
    #1

    When using antialising

    	graphicsView->setRenderHint( QPainter::Antialiasing );
    

    curves are nicely drawn but straight lines that are drawn with a pen of size 1 have a width of two pixels instead of one, which is not so nice.

    Is there a way to selectively indicate which items needs to be antialiased?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      You can control antialiasing on the QPainter level using setRenderHint.
      So, for custom items where you write the paint method yourself, you should be able to decide whether to draw with antialiasing on or off (or even draw some parts with, some parts without).

      J 1 Reply Last reply
      1
      • A Asperamanca

        You can control antialiasing on the QPainter level using setRenderHint.
        So, for custom items where you write the paint method yourself, you should be able to decide whether to draw with antialiasing on or off (or even draw some parts with, some parts without).

        J Offline
        J Offline
        JanLaloux
        wrote on last edited by
        #3

        @Asperamanca Excellent idea. I've added an example class for those interested in the implementation:

        class CurveItem : public QGraphicsItem {
        public:
        	CurveItem( const int cX1, const int cY1, const int cX2, const int cY2, QGraphicsScene *scene ):
        		X1(cX1),
        		Y1(cY1),
        		X2(cX2),
        		Y2(cY2)
        	{
        		Path.moveTo( cX1, cY1 );
        		Path.quadTo( cX1 + ( cX2-cX1 )/2, cY1+30, cX2, cY2 );
        		scene->addItem( this );
        	}
        
        	~CurveItem(){}
        
            QRectF boundingRect() const {
        		return QRectF( X1, Y1, X2, Y2 );
            }
        
        	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option=0, QWidget *widget=0){
        		painter->setPen( QPen(QBrush(Qt::red), 1, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin ) );
        		painter->setRenderHint( QPainter::Antialiasing );
        		painter->drawPath( Path );
        	}
        
        
        private:
        	QPainterPath Path;
        	int X1, Y1, X2, Y2;
        };
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved