Results 1 to 6 of 6

Thread: repainting through paintEvent() function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default repainting through paintEvent() function

    Hi
    i am making an application in which i initially drew some ellipse and circle,
    now the problem i am facing is that that then i got a signal from other class
    at this signal i want to repaint inside the previously drawn ellipse so
    in my paintEvent() function how could i define that that code should work only when signal is emmited or do i have to define another slot with a painter function to listen to that signal...

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: repainting through paintEvent() function

    Keep a variable in your class which will be used in the paintEvent what to draw and what to not
    like
    Qt Code:
    1. OnMySignal()
    2. {
    3. drawInsideEllipse = true;
    4. }
    5.  
    6. paintEvent()
    7. {
    8. if(drawInsideEllipse)
    9. // draw what u want ;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Hope u get the idea

  3. The following user says thank you to aamer4yu for this useful post:

    salmanmanekia (6th August 2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: repainting through paintEvent() function

    thanks aamir...i already did the same thing ...initially i was lost in the details of my classes and signals ,so i just wasnt able to think ..anyways thanks again

  5. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: repainting through paintEvent() function

    by the way i also tried the repaint() slot ,i know it is not useful in my case but i just got an error,the declaration is as follows in my
    .h file
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    .cpp
    Qt Code:
    1. //in constructor
    2. r1(x,y,w,h,QRegion::Ellipse);
    3. //in a slot
    4. repaint(r1) // error thrown here;
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: repainting through paintEvent() function

    Well, using repaint might not be a good idea...

    From the docs -
    void QWidget::repaint () [slot]
    Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden.
    We suggest only using repaint() if you need an immediate repaint, for example during animation. In almost all circumstances update() is better, as it permits Qt to optimize for speed and minimize flicker.
    Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion.
    See also update(), paintEvent(), and setUpdatesEnabled().
    Use update() instead. Modify ur code accordingly. I hope urs is not a animation requirement

  7. #6
    Join Date
    Apr 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: repainting through paintEvent() function

    SOlution to fix ur bug:
    I guess u r trying to use the constructor
    Qt Code:
    1. QRegion ( int x, int y, int w, int h, RegionType t = Rectangle )
    To copy to clipboard, switch view to plain text mode 

    For that in the constructor

    Qt Code:
    1. 1.
    2. //in constructor
    3. 2.
    4. r1=QRegion ((x,y,w,h,QRegion::Ellipse);
    5. 3.
    6. //in a slot
    7. 4.
    8. repaint((const QRegion)r1) // error thrown here;
    9. 5.
    To copy to clipboard, switch view to plain text mode 

    try out this
    "A fool can ask More questions that a wise man cannot answer"
    /home/nithyanair/Pics/image.jpg

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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
  •  
Qt is a trademark of The Qt Company.