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. QGraphicsLineItem line width
QtWS25 Last Chance

QGraphicsLineItem line width

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 9.8k Views
  • 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.
  • D Offline
    D Offline
    Doru
    wrote on last edited by
    #1

    Hi ,
    Can somebody explain how to draw a QGraphicsLineItem's line with a width of 1 pixel?
    I have set the painter's pen width to 1

    p->setPen(QPen(QColor(213,164,83),1));
    p->drawLine(line());

    but the line width is grater than 1.

    If I draw line on a QLabel or QWidget paint methods it works ok

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tony
      wrote on last edited by
      #2

      Hi,

      line width is relative to the "distance" between the view and the scene. More you zoom, more the width grows. If you want the line to be always 1, independently from the "distance", you should set the pen width to 0.

      Look at the QPen::setWidth documentation.

      Tony.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Doru
        wrote on last edited by
        #3

        Hi,
        Thanks for suggestion but it seams I get the same display.
        Anyway I have no zoom set (yet).
        pen.setWidth(0);
        p->setPen(pen);
        p->drawLine(line());
        !http://1.bp.blogspot.com/_8XPM3BE3B_E/TPSfDZLe7aI/AAAAAAAAAHs/FPpGulCw5V0/s1600/Untitled.png(Print)!

        On the ruler I get the correct display (1 pixel) and on the scene ...?!

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blex
          wrote on last edited by
          #4

          Maybe it is the result of anti-aliasing?

          What type of "p" variable in your code?


          Oleksiy Balabay

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Doru
            wrote on last edited by
            #5

            void GuideItem::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget * )
            How can I modify this aliasing feature/setting?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              blex
              wrote on last edited by
              #6

              [quote author="Doru" date="1291103107"]void GuideItem::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget * )
              [/quote]

              Is GuideItem inherited from QGraphicsLineItem? If "yes" then why do you paint line yourself? Does call to QGraphicsLineItem::paint() produce the same result?


              Oleksiy Balabay

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Doru
                wrote on last edited by
                #7

                Yes , it produces the same result.
                I paint it myself because I want to modify line color when selected.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  blex
                  wrote on last edited by
                  #8

                  As I said above, I think that it is anti-aliasing effect. Try to play with QPainter settings:

                  @
                  void QPainter::setRenderHint ( RenderHint hint, bool on = true )
                  @


                  Oleksiy Balabay

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Doru
                    wrote on last edited by
                    #9

                    I did'n succeed with render hints.
                    Can this problem appear because it is a graphic item?

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      blex
                      wrote on last edited by
                      #10

                      Sorry, no answer. Try to go step-by-step in debug mode in Qt library code (for example, set break-point in QPainter::drawLine() function). Maybe you will understand what happens.


                      Oleksiy Balabay

                      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