Qt5 official demo release set 34 -- Concentric Circles Example, qt5concentric

Source: Internet
Author: User

Qt5 official demo release set 34 -- Concentric Circles Example, qt5concentric

All articles in this series can be viewed here in http://blog.csdn.net/cloud_castle/article/category/2123873

Link to Qt5 official demo getting set 33 -- Qt Quick Examples-Window and Screen


It seems that this series has not been updated for a while. On the one hand, a lot of things are coming together, a little more busy than it was before; but there is no time to squeeze it out, one of the more important reasons is that it is difficult to find a particularly suitable Demo for this topic. Some Demo content is very rare, and some demos are too basic. I always hope to pick out some knowledge points that people often have access to and need to know ~


Every official Demo of Qt has a point of attention. Every time you paste all the code, there may be more and more duplicates in this series... So from the beginning of this article, we will just pick out the key code and introduce it with great emphasis (* ^__ ^ *)


Well, let's get started with today's question: Concentric Circles Example

We all know that you can use paintEvent () to draw an ellipse in Qt.

painter.drawEllipse(QRect(-diameter / 2, -diameter / 2, diameter, diameter));

Then, the effect of drawing multiple concentric circles is like the following:

(The Demo running effect under the magnifier effect)


First, let's put this and Its incircle edges aside. If you are careful, you may find that these concentric circles are always very close to each other, and we clearly draw the same distance concentric circles? In fact, the answer is very simple. It is the result of rounding the integer coordinate value. After knowing the source of the problem, it is easy to solve it.

Qt provides us with another drawEllipse () that accepts the QRectF () parameter ():

painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0, diameter, diameter));


Is there any better? On the one hand, we have indeed obtained an equi-width concentric circle, and on the other hand, it seems to be round, so the conspicuous straight line is not that long.


If you want to get a more round circle, we can set the painter's anti-tooth effect QPainter: Antialiasing, simply put, it uses the sampling algorithm to perform an average operation between the Sawtooth pixels and the surrounding pixels at the image edge, and increase the number of pixels, in this way, the smooth transition of regional pixels is formed. However, the side effect of this operation is that the image is blurred.


DrawEllipse (QRect () + anti-aliasing:

painter.setRenderHint(QPainter::Antialiasing);painter.drawEllipse(QRect(-diameter / 2, -diameter / 2, diameter, diameter));


DrawEllipse (QRectF () + anti-aliasing:

painter.setRenderHint(QPainter::Antialiasing);painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0, diameter, diameter));



Finally, let's take a look at the interface of the entire program:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.