Results 1 to 6 of 6

Thread: Draw Line

  1. #1
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Draw Line

    Hi,

    I want to draw line without writing code in paintEvent() function. I don't want to declare
    or define the PaintEvent() function. I want to write my own function.

    Thanks and Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Draw Line

    Let's see what the documentation says:

    Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.
    So, if you want to paint directly on the widget, you need to implement the paint event. You can call your own functions from within the paint event.

    But, you can also paint on a pixmap or picture, then you don't need the paint event. But you need a widget that displays the picture (a QLabel for example).

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Draw Line

    On other option is also to install an event filter, catch the paint event and then draw there.

  4. #4
    Join Date
    Oct 2010
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Draw Line

    What do you like to draw exactly? Do you like to draw a line on an existing widget?
    Then you have to re-implement the paintEvent()-Method in a subclass of the widget. You can call Subclass:aintEvent(event); to draw the widget and then use QPainter to draw extra stuff on it...

    It is possible to write your own paint()-Funktion but you have to call it from the paintEvent()-Method, otherwise it will not work out.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Draw Line

    Quote Originally Posted by Ceelaz View Post
    It is possible to write your own paint()-Funktion but you have to call it from the paintEvent()-Method, otherwise it will not work out.
    That is as said not true! You can fetch a paint event and draw from outside the widget in any event filter without to touch paintEvent().

  6. #6
    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: Draw Line

    Well... go ahead.. write your own function..
    in your function.. draw the line onto a pixmap.. and then set this pixmap on a label..

    but that wud be inefficient,, dont you think so ?

Similar Threads

  1. Draw a line
    By Daan in forum KDE Forum
    Replies: 1
    Last Post: 27th August 2009, 17:29
  2. Draw Line
    By aloysiusjegan in forum Qwt
    Replies: 4
    Last Post: 12th February 2009, 11:02
  3. Draw line on Mainwindow
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2009, 08:54
  4. Best way to draw a Line
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2008, 09:57

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.