Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QtPen draw wrong border for Rectangle (PyQt)



  • 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


  • Lifetime Qt Champion

    Hi,

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



  • 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



  • 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???????????


Log in to reply