Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:13:49+00:00 2026-06-10T14:13:49+00:00

I am new to Python. I have drawn polygon and circle with fixed coordinates.

  • 0

I am new to Python. I have drawn polygon and circle with fixed coordinates. Now I want to move this polygon and circle using mouse to some other place on window. Please guide me how can I do it?

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MyFrame(QWidget):
    def __init__(self, parent=None):
            QWidget.__init__(self)

    def paintEvent(self, event=None):
            paint=QPainter(self)
            paint.setPen(QPen(QColor(Qt.green).dark(150),1,Qt.SolidLine))
            segColor=QColor(Qt.green).dark(150)
            paint.setBrush(segColor)
            paint.setBrushOrigin(QPoint(225,225))
            polygon=QPolygon([QPoint(250,175), QPoint(265,175), QPoint(250,190), QPoint(265,190),QPoint(250,175)])
            paint.drawPolygon(polygon)
            paint.setPen(QPen(QColor(Qt.red),1,Qt.SolidLine))
            paint.setBrush(QBrush(Qt.NoBrush))
            polygon1=QPolygon([QPoint(250,300), QPoint(250,500), QPoint(350,500), QPoint(350,300)])
            paint.drawPolyline(polygon1)
            paint.drawEllipse(50,50,50,50)


app=QApplication(sys.argv)
f=MyFrame()
f.show()
app.exec_()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:13:51+00:00Added an answer on June 10, 2026 at 2:13 pm

    You should look into the QGraphicsView instead of what you are doing, it has this all built in already.

    http://doc.qt.nokia.com/4.7-snapshot/qgraphicsview.html

    http://doc.qt.nokia.com/4.7-snapshot/qgraphicsscene.html

    from PyQt4 import QtGui, QtCore
    
    class MyFrame(QtGui.QGraphicsView):
        def __init__( self, parent = None ):
            super(MyFrame, self).__init__(parent)
    
            self.setScene(QtGui.QGraphicsScene())
    
            # add some items
            x = 0
            y = 0
            w = 45
            h = 45
            pen = QtGui.QPen(QtGui.QColor(QtCore.Qt.green))
            brush = QtGui.QBrush(pen.color().darker(150))
    
            item = self.scene().addEllipse(x, y, w, h, pen, brush)
            item.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
    
    if ( __name__ == '__main__' ):
        app = QtGui.QApplication([])
        f = MyFrame()
        f.show()
        app.exec_()
    

    Edit: Showing how to create a QPainterPath

    from PyQt4 import QtGui, QtCore
    
    class MyFrame(QtGui.QGraphicsView):
        def __init__( self, parent = None ):
            super(MyFrame, self).__init__(parent)
    
            scene = QtGui.QGraphicsScene()
            self.setScene(scene)
    
            # add some items
            x = 0
            y = 0
            w = 45
            h = 45
            pen   = QtGui.QPen(QtGui.QColor(QtCore.Qt.green))
            brush = QtGui.QBrush(pen.color().darker(150))
    
            item = scene.addEllipse(x, y, w, h, pen, brush)
            item.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
    
            # create an open path
            path = QtGui.QPainterPath()
            path.moveTo(-w, -h)
            path.lineTo(-w, h)
            path.lineTo(w, h)
            path.lineTo(w, -h)
    
            clr   = QtGui.QColor('blue')
            clr.setAlpha(120)
            brush = QtGui.QBrush(clr)
            pen   = QtGui.QPen(QtCore.Qt.NoPen)
            fill_item = scene.addRect(-w, y, w*2, h, pen, brush)
            path_item = scene.addPath(path)
    
    if ( __name__ == '__main__' ):
        app = QtGui.QApplication([])
        f = MyFrame()
        f.show()
        app.exec_()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to Python and have a question. Currently I'm using this to
I'm new to python and have been trying to figure this out all day.
I'm new to Python (I have been programming in Java for multiple years now
I have a python package previously installed via apt(by default). Now I want to
I'm new to python and have been going through some tutorials on log parsing
I am very new with Python and I have just received this message while
I'm new to Python and I have a solution for this but it seems
I am new to Python and have been studying its fundementals for 3 months
I'm new to python and have hit a problem with an SQL query I'm
hello im new to python and have been reading over the documentation and am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.