Results 1 to 2 of 2

Thread: Decide two items on top of each other,is there a z-index?

  1. #1
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Platforms
    Windows

    Default Decide two items on top of each other,is there a z-index?

    I am using pyqt4 and I have drawn a line and a rectangle on.Now since they are on the same coordinate they overlap. I wanted to know if there is a z-index(used in css) sort of a thing which I can use to show or hide either the line on top of the triangle or vice versa.Also adding the code by how I have a line and rectangle.
    Qt Code:
    1. from PyQt4 import QtGui
    2. from PyQt4 import QtCore
    3. import pyqtgraph as pg
    4. import webcolors
    5.  
    6.  
    7. class LineSegmentItem(pg.GraphicsObject):
    8. def __init__(self, p1, p2,color):
    9. pg.GraphicsObject.__init__(self)
    10. self.p1 = p1
    11. self.p2 = p2
    12. self.color=color
    13. self.generatePicture()
    14.  
    15. def generatePicture(self):
    16. self.picture = QtGui.QPicture()
    17. self.p = QtGui.QPainter(self.picture)
    18. self.p.setPen(pg.mkPen(self.color))
    19. self.p.drawLine(QtCore.QPoint(self.p1[0], self.p1[1]), QtCore.QPoint(self.p2[0], self.p2[1]))
    20. self.p.end()
    21.  
    22. def paint(self, p, *args):
    23. p.drawPicture(0, 0, self.picture)
    24.  
    25. def boundingRect(self):
    26. return QtCore.QRectF(self.picture.boundingRect())
    27.  
    28. def modifyColor(self,color):
    29. self.color=color
    30. self.generatePicture()
    31.  
    32. def stretchLine(self,toSecondCoordinate):
    33. self.p2[0]=toSecondCoordinate
    34. self.update()
    35.  
    36. def getToSecondCoordinate(self):
    37. return self.p2[0]
    38.  
    39.  
    40. class CircleItem(pg.GraphicsObject):
    41. def __init__(self, center, radius):
    42. pg.GraphicsObject.__init__(self)
    43. self.center = center
    44. self.radius = radius
    45. self.generatePicture()
    46.  
    47. def generatePicture(self):
    48. self.picture = QtGui.QPicture()
    49. p = QtGui.QPainter(self.picture)
    50. p.setPen(pg.mkPen('w'))
    51. p.drawEllipse(self.center[0], self.center[1], self.radius * 2, self.radius * 2)
    52. p.end()
    53.  
    54. def paint(self, p, *args):
    55. p.drawPicture(0, 0, self.picture)
    56.  
    57. def boundingRect(self):
    58. return QtCore.QRectF(self.picture.boundingRect())
    59.  
    60.  
    61. class RectangleItem(pg.GraphicsObject):
    62. def __init__(self, p1,p2,color,tickSize):
    63. pg.GraphicsObject.__init__(self)
    64. self.topLeft = p1
    65. self.size = [abs(p2[0]-p1[0]),tickSize]
    66. self.color=color
    67. self.generatePicture()
    68.  
    69. def generatePicture(self):
    70. self.picture = QtGui.QPicture()
    71. p = QtGui.QPainter(self.picture)
    72. p.setPen(pg.mkPen(self.color))
    73.  
    74. r,g,b=self.color
    75. p.setBrush(QtGui.QColor(r,g,b))
    76. tl = QtCore.QPointF(self.topLeft[0], self.topLeft[1])
    77. size = QtCore.QSizeF(self.size[0], self.size[1])
    78. p.drawRect(QtCore.QRectF(tl, size))
    79. p.end()
    80.  
    81. def paint(self, p, *args):
    82. p.drawPicture(0, 0, self.picture)
    83.  
    84. def boundingRect(self):
    85. return QtCore.QRectF(self.picture.boundingRect())
    86.  
    87. def modifyColor(self,color):
    88. self.color=color
    89. self.generatePicture()
    90.  
    91. def stretchLine(self,toSecondCoordinate):
    92. self.size[0]=toSecondCoordinate-self.topLeft[0]
    93. self.update()
    94.  
    95. def getToSecondCoordinate(self):
    96. return self.size[0]
    To copy to clipboard, switch view to plain text mode 

    pic.PNG

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Decide two items on top of each other,is there a z-index?

    Yes, see QGraphicsItem::zValue().

    Cheers,
    _

Similar Threads

  1. Help me decide which ORDBMS should I use
    By batman in forum Newbie
    Replies: 3
    Last Post: 5th January 2015, 18:38
  2. Replies: 0
    Last Post: 11th February 2014, 18:42
  3. Decide the arrow graphics item's docking point
    By sajis997 in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2012, 23:46
  4. How to decide which SIGNAL to emit?
    By TheIndependentAquarius in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2011, 16:09
  5. Replies: 3
    Last Post: 13th April 2011, 07:43

Tags for this Thread

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.