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. [Solved] QGraphicsScene/View displays empty rect
Forum Updated to NodeBB v4.3 + New Features

[Solved] QGraphicsScene/View displays empty rect

Scheduled Pinned Locked Moved General and Desktop
5 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.
  • W Offline
    W Offline
    Woomla
    wrote on last edited by
    #1

    Hi,

    If I add a rect to a QGraphicsScene with a zero height, the rect is still displayed on the QGraphicsView.

    !http://i42.tinypic.com/2pt8dg5.jpg!

    Created with:

    @QMatrix matrix;
    matrix.scale(8, -8);
    graphicsView.setMatrix(matrix);

    scene.addRect(0, 0, 10, 5, QPen(QColor("yellow"), 1));
    scene.addRect(0, 0, 1, 0, QPen(QColor("red"), 1));
    scene.addRect(5, 0, 5, 0, QPen(QColor("blue"), 0), QBrush(QColor("green"), Qt::NoBrush));
    @

    The complete source file is here: "Empty Rect Example":http://pastebin.com/64tkStUe

    What can I do to make this (red and blue) rect to not display anything but still be there?

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

      The pen specifies the border of the rectangle. Basically, a rectangle of height zero behaves like a line, so it's logical that something will be painted.

      1. Use a Brush instead of a Pen to fill the interior of the rectangle instead of painting the border. A rectangle with height zero should have no interior, and therefore not draw
      2. You can always write your own rectangle item that behaves exactly as you want...
      1 Reply Last reply
      0
      • W Offline
        W Offline
        Woomla
        wrote on last edited by
        #3

        Great!

        I've changed line 5,6 and 7 to:

        @
        scene.addRect(0, 0, 10, 5, QPen(QBrush(Qt::NoBrush), 0), QBrush(QColor("yellow")));
        scene.addRect(0, 0, 1, 0, QPen(QBrush(Qt::NoBrush), 0), QBrush(QColor("#red")));
        scene.addRect(5, 0, 5, 0, QPen(QBrush(Qt::NoBrush), 0), QBrush(QColor("#blue")));
        @

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

          I think you can simplify to

          @scene.addRect(0, 0, 10, 5, QPen(Qt::NoPen), QBrush(QColor("yellow")));@

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Woomla
            wrote on last edited by
            #5

            Cool! Tx.

            And of course '#red' should be just 'red'.

            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