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

  • Home
  • SEARCH
  • 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 6916987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:40:23+00:00 2026-05-27T09:40:23+00:00

I’m trying to make a very basic image creator using PySide. But I’m having

  • 0

I’m trying to make a very basic image creator using PySide. But I’m having some troubles to draw things.

This is the portion of my script responsible for the draw area:

class Area(QWidget):

   global x1
   global y1
   global x2
   global y2
   try:
      x1
   except NameError:
      x1=0
   try:
      y1
   except NameError:
      y1=0

   try:
      x2
   except NameError:
      x2=100
   try:
      y2
   except NameError:
      y2=100

   def mousePressEvent(self, me):
      global x1     
      global y1
      x1 = me.x()
      y1 = me.y()

   def mouseMoveEvent(self, mo):
      global x2
      global y2
      x2 = mo.x()
      y2 = mo.y()
      self.update()

   def paintEvent(self, pe):
      global paint
      paint = QPainter()
      paint.begin(self)
      paint.drawLine(x1,y1,x2,y2)
      paint.save()
      paint.restore()

blankarea = Area()
blankarea.show()

Basicaly, what the script does is just draw a line based on mouse events. However, every time the mouse click event occurs (responsible for start a line) it erases the line previously made, even after using QPainter.save() and QPainter.restore(). What could be causing this problem?

  • 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-05-27T09:40:23+00:00Added an answer on May 27, 2026 at 9:40 am

    The paintEvent() method is repainting the entire widget every time it is called. The drawing from the previous calls is completely replaced with the results of each future paintEvent() call.

    If you want the effect you are describing, you will need to accumulate the points and draw the entire sequence of them each time.

    From the docs:
    http://pyside.github.io/docs/pyside/PySide/QtGui/QWidget.html#PySide.QtGui.PySide.QtGui.QWidget.paintEvent

    When the paint event occurs, the update region has normally been
    erased, so you are painting on the widget’s background.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.