Results 1 to 7 of 7

Thread: Adding qpaint object to a Layout

  1. #1
    Join Date
    Feb 2008
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Adding qpaint object to a Layout

    I am rewriting a bit of code where there use to be a canvas and I am replacing it with a paint object. When I added the canvas to my gui all I had to do is tb->addWidget(canvas), where tb is a vertical layout. When I try to add the paint object to tb I get the error no matching function for call to ‘QHBoxLayout::addWidget(QPainter*&). I was wondering how would I add the paint object to tb where the canvas use to be.

    When I say paint object, I mean QPaint paint. Not sure what the terminology is here. I am very new to QT.

    Sorry if this is confusing to anybody.

    Thanks

  2. #2
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Adding qpaint object to a Layout

    Quote Originally Posted by Rooster View Post
    I am rewriting a bit of code where there use to be a canvas and I am replacing it with a paint object. When I added the canvas to my gui all I had to do is tb->addWidget(canvas), where tb is a vertical layout. When I try to add the paint object to tb I get the error no matching function for call to ‘QHBoxLayout::addWidget(QPainter*&). I was wondering how would I add the paint object to tb where the canvas use to be.

    When I say paint object, I mean QPaint paint. Not sure what the terminology is here. I am very new to QT.

    Sorry if this is confusing to anybody.

    Thanks
    Here, You can use QGraphicsView object in place of QCanvas..
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  3. #3
    Join Date
    Feb 2008
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Adding qpaint object to a Layout

    Quote Originally Posted by ashukla View Post
    Here, You can use QGraphicsView object in place of QCanvas..

    That function was introduced in version 4.2 and I am using Qt 3.3, and can't upgrade because we have a commercial license for that version. Do you have any other suggestions?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding qpaint object to a Layout

    You mean a QPainter?
    You can't add a QPainter to anything. QPainter is used just to paint on paint devices.
    If you want to create a graphical object to substitute the canvas, you can create a QWidget subclass and paint on it.

    Regards

  5. #5
    Join Date
    Feb 2008
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Adding qpaint object to a Layout

    Quote Originally Posted by marcel View Post
    You mean a QPainter?
    You can't add a QPainter to anything. QPainter is used just to paint on paint devices.
    If you want to create a graphical object to substitute the canvas, you can create a QWidget subclass and paint on it.
    Yes, I mean QPainter. Sorry about that. Is creating a QWidget subclass the best way to go? What I am doing is I have three checkboxes that correspond to three different graphs. If two of the boxes are checked then two of the graphs are drawn. If all three boxes are checked then all three graphs are drawn. I decided to use QPainter instead of canvas because of issues with the scaling and drawing the lines in canvas was getting problematic. Could there be a better way of doing this than using QPainter?


    Thanks

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding qpaint object to a Layout

    But you don't understand.
    You must use QPainter *AND* QWidget. You use the painter to draw on the widget. That is the only way. What would you do with a QPainter alone?

    And subclassing QWidget shouldn't be a problem.

  7. #7
    Join Date
    Feb 2008
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Adding qpaint object to a Layout

    Quote Originally Posted by marcel View Post
    But you don't understand.
    You must use QPainter *AND* QWidget. You use the painter to draw on the widget. That is the only way. What would you do with a QPainter alone?

    And subclassing QWidget shouldn't be a problem.
    I think I get it now. Create a QWidget that will do all of the QPainter things to it. Then build the other widget around it. Is this correct?

Similar Threads

  1. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  2. Adding numbers to circles in QPaint
    By therealjag in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2006, 10:21

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.