PDA

View Full Version : Adding qpaint object to a Layout



Rooster
12th February 2008, 03:12
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

ashukla
12th February 2008, 04:20
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 (http://doc.trolltech.com/4.3/qgraphicsview.html) object in place of QCanvas..

Rooster
12th February 2008, 17:09
Here, You can use QGraphicsView (http://doc.trolltech.com/4.3/qgraphicsview.html) 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?

marcel
12th February 2008, 17:12
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

Rooster
12th February 2008, 17:49
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

marcel
12th February 2008, 18:03
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.

Rooster
13th February 2008, 13:12
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?