Results 1 to 5 of 5

Thread: QtPen draw wrong border for Rectangle (PyQt)

  1. #1
    Join Date
    Sep 2014
    Posts
    18
    Thanks
    2
    Qt products
    Platforms
    Unix/X11 Windows

    Default QtPen draw wrong border for Rectangle (PyQt)

    Hello everyone!
    I try to draw the Rectangle:
    Qt Code:
    1. paint.setBrush(QtGui.QBrush(some gradient))
    2. paint.setPen(QtGui.QPen(QtGui.QColor("black"), 1))
    3. paint.drawRect(x, y, width, height)
    To copy to clipboard, switch view to plain text mode 
    as the result, this:

    rhs8z5.jpg

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtPen draw wrong border for Rectangle (PyQt)

    Please provide a minimal compilation example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2014
    Posts
    18
    Thanks
    2
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: QtPen draw wrong border for Rectangle (PyQt)

    Qt – 4.8.4
    PyQt – 4.9.6
    Windows 7

    Qt Code:
    1. class Chart(QtGui.QWidget):
    2. def __init__(self, parent=None):
    3. super(Chart, self).__init__(parent)
    4. def paintEvent(self, Event):
    5. paint = QtGui.QPainter(self)
    6. paint.setBrush(QtGui.QColor("#808080"))
    7. paint.drawRect(40, 20, 580, 410)
    8. paint.setPen(QtGui.QPen(QtGui.QColor("#ffffff"), 1))
    9. grad = QtGui.QLinearGradient(0, 20, 0, 410)
    10. grad.setColorAt(0.0, QtGui.QColor("#fefdc5"))
    11. grad.setColorAt(1.0, QtGui.QColor("#f3c169"))
    12. paint.setBrush(QtGui.QBrush(grad))
    13. paint.drawRect(70, 430, 25, -100)
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2014
    Posts
    18
    Thanks
    2
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: QtPen draw wrong border for Rectangle (PyQt)

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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtPen draw wrong border for Rectangle (PyQt)

    Maybe because of the design mentioned in QRect::bottomRight()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. 3D Border Style for Rectangle in QML
    By tauseef in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2013, 07:10
  2. Replies: 1
    Last Post: 24th May 2010, 12:57
  3. Replies: 0
    Last Post: 14th January 2010, 07:48
  4. PyQt... What am I doing wrong?!
    By Richie in forum Newbie
    Replies: 2
    Last Post: 4th September 2009, 18:14
  5. Replies: 2
    Last Post: 5th July 2008, 20:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.