On Sat, Dec 8, 2018, 8:24 AM likage <dissidia....@gmail.com> wrote:

> I am slightly confused now...
> I apologize in advance, not an excuse but this is my first time dealing
> with QGraphicsXXX and have it integrated with the 'normal' widgets..
>
> In the BaseWidget script - filled_round_rect(), it appears that the icon
> creation is made there and so I added this part in:
>
> def filled_round_rect():
>    ...
>    ...
>    painter.fillPath(rounded_rect, colour)
>
>     # I added the following line
>    self.pixmapItem = QtGui.QGraphicsPixmapItem(self.type_icon())
>
>     if self.ICON:
>        top_right = self.boundingRect().topRight()
>        painter.drawPixmap(
>            top_right.x() - 35,
>            top_right.y() + 5,
>            self.pixmapItem # I replace this with self.type_icon()
>        )
>
>
> and got the following error... I had thought that it will work, as the
> BaseWidget is within QGraphicsScene?
>
> # TypeError: # 'PySide2.QtGui.QPainter.drawPixmap' called with wrong
> argument types:
> #   PySide2.QtGui.QPainter.drawPixmap(float, float,
> PySide2.QtWidgets.QGraphicsPixmapItem)
> # Supported signatures:
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPoint,
> PySide2.QtGui.QPixmap)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPoint,
> PySide2.QtGui.QPixmap, PySide2.QtCore.QRect)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPointF,
> PySide2.QtGui.QPixmap)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QPointF,
> PySide2.QtGui.QPixmap, PySide2.QtCore.QRectF)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRect,
> PySide2.QtGui.QPixmap)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRect,
> PySide2.QtGui.QPixmap, PySide2.QtCore.QRect)
> #   PySide2.QtGui.QPainter.drawPixmap(PySide2.QtCore.QRectF,
> PySide2.QtGui.QPixmap, PySide2.QtCore.QRectF)
> #   PySide2.QtGui.QPainter.drawPixmap(int, int, PySide2.QtGui.QPixmap)
> #   PySide2.QtGui.QPainter.drawPixmap(int, int, PySide2.QtGui.QPixmap,
> int, int, int, int)
> #   PySide2.QtGui.QPainter.drawPixmap(int, int, int, int,
> PySide2.QtGui.QPixmap)
> #  PySide2.QtGui.QPainter.drawPixmap(int, int, int, int,
> PySide2.QtGui.QPixmap, int, int, int, int)
>

Sorry, I had misunderstood part of your previous question based on your
original example of wanting to do a clickable icon with a Qlabel or
Qpushbutton. And I thought you were trying to integrate QWidget into
QGraphicsScene. It is still true that you should avoid them as much as
possible and do all drawing through QGraphicsItem classes.

Your current error is exactly what the exception says. You can't pass a
QGraphics item to the QPainter draw like that. You don't even need a custom
draw call if you are using a QGraphicsPixmapItem for your icon. Just add it
as a child to your item and position it where it needs to go. It will draw
itself and also give you the mouse press handler for its bounds.
Otherwise if you continue drawing your own pixmap (which is fine) then you
have to handle the mouse press in that main item and test if it hits the
bounds for the icon you drew. I find it's a bit easier if the items are
just composed and encapsulate their own event handling. Just think of
parent-child composition with QGraphicsItems

Hope that makes sense.


>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/7d37d380-c1ae-447c-a47d-aacd19976bc0%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/7d37d380-c1ae-447c-a47d-aacd19976bc0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2ZvvahYD3vdBeMnuf%3D73%3DH11fsY-diwP-MyRuLeF2rrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to