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. QtPen draw wrong border for Rectangle (PyQt)

QtPen draw wrong border for Rectangle (PyQt)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.7k 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.
  • BuccaneerB Offline
    BuccaneerB Offline
    Buccaneer
    wrote on last edited by
    #1

    Hello everyone!
    I try to draw the Rectangle:
    @paint.setBrush(QtGui.QBrush(some gradient))
    paint.setPen(QtGui.QPen(QtGui.QColor("black"), 1))
    paint.drawRect(x, y, width, height)
    @
    as the result, this:

    !http://i60.tinypic.com/rhs8z5.jpg(sample)!

    Why QPen border on top and on right side are shifted?
    left and bottom border correct

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should give more information, like the complete painting code, PyQt/Qt/OS you are using.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • BuccaneerB Offline
        BuccaneerB Offline
        Buccaneer
        wrote on last edited by
        #3

        Qt - 4.8.4
        PyQt - 4.9.6
        Windows 7

        As for you SGaist my friend, code as he is:
        @
        class Chart(QtGui.QWidget):
        def init(self, parent=None):
        super(Chart, self).init(parent)
        def paintEvent(self, Event):
        paint = QtGui.QPainter(self)
        paint.setBrush(QtGui.QColor("#808080"))
        paint.drawRect(40, 20, 580, 410)
        paint.setPen(QtGui.QPen(QtGui.QColor("#ffffff"), 1))
        grad = QtGui.QLinearGradient(0, 20, 0, 410)
        grad.setColorAt(0.0, QtGui.QColor("#fefdc5"))
        grad.setColorAt(1.0, QtGui.QColor("#f3c169"))
        paint.setBrush(QtGui.QBrush(grad))
        paint.drawRect(70, 430, 25, -100)
        @

        I hope this will help

        1 Reply Last reply
        0
        • BuccaneerB Offline
          BuccaneerB Offline
          Buccaneer
          wrote on last edited by
          #4

          At last I understood myself (((
          The problem occurs only if I'm trying to set (draw) a rectangle height from bottom to top using a negative value (drawRect(0, 0, 20, -100)).
          If I set (draw) from top to bottom (drawRect(0, 0, 20, 100)) the rectangle looks perfect with no shifts.
          Whyyyyyyyyyyyyyyyyyyyy???????????

          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