Results 1 to 2 of 2

Thread: Problems with limited mouseMoveEvent

  1. #1
    Join Date
    Oct 2011
    Posts
    2
    Qt products
    Platforms
    Windows

    Question Problems with limited mouseMoveEvent

    Hi all,

    i'm trying to do a very simple thing but i'm not able to get the result i want ;(

    I'm using QtSvg library. I want to display a shape and move it through the QGraphicsScene. I have done it and it works fine. The problem comes when i try to limit its movement, for example, if i want to limit its movement in x to 20 pixels from its original position.
    The mouseMoveEvent function that i have implemented is show below where "self.posi" is the initial position of the shape...

    Qt Code:
    1. class SvgElement(QtSvg.QGraphicsSvgItem):
    2. ...
    3. ...
    4. ...
    5.  
    6. def mouseMoveEvent (self, e):
    7. xValue = 0
    8. if self.pos().x() <= self.posi.x()+threshold and self.pos().x() >= self.posi.x()-threshold:
    9. super(SvgElement,self).mouseMoveEvent (e)
    10. else:
    11. if self.pos().x() >= self.posi.x()+threshold:
    12. xValue = self.posi.x()+self.threshold
    13. elif self.pos().x() < self.posi.x()-threshold:
    14. xValue = self.posi.x()-threshold
    15.  
    16. self.setPos(xValue, self.pos().y())
    To copy to clipboard, switch view to plain text mode 

    I'm not able to make it work, any idea what is it happening?
    Any ideas will be appreciated

  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: Problems with limited mouseMoveEvent

    Such things are usually done using QGraphcsItem::itemChange()
    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. String length limited in QTableWidgetItem
    By joseprl89 in forum Qt Programming
    Replies: 4
    Last Post: 25th September 2013, 12:34
  2. mouseMoveEvent and leaveEvent Problems
    By Furkan in forum Qt Programming
    Replies: 9
    Last Post: 29th December 2010, 14:25
  3. Does QSqlTableModel have limited capacity?
    By metdos in forum Qt Programming
    Replies: 2
    Last Post: 1st January 2010, 22:06
  4. filter signal to limited slots
    By sriky27 in forum Qt Programming
    Replies: 17
    Last Post: 26th March 2009, 16:59
  5. Why are actions limited to menus and toolbars?
    By Paul Drummond in forum Qt Programming
    Replies: 16
    Last Post: 3rd March 2006, 12:05

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.