PDA

View Full Version : QtPen draw wrong border for Rectangle (PyQt)



Goodwin
9th October 2014, 11:11
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:

10663

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

wysota
9th October 2014, 21:55
Please provide a minimal compilation example reproducing the problem.

Goodwin
10th October 2014, 06:29
Qt – 4.8.4
PyQt – 4.9.6
Windows 7



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)

Goodwin
17th October 2014, 13:34
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???????????

wysota
17th October 2014, 15:53
Maybe because of the design mentioned in QRect::bottomRight()?