PDA

View Full Version : whether Qcanvas objects be added in QLayout



Amrita Singh
23rd February 2009, 11:00
hello friends

this question would seem simple but i am needing help.

i have to add a QCanvasEllipse to my QHBoxlayout.but it doesnt work
QBoxlayout *toplayout=new QHBoxLayout(this);
QCanvas *c=new QCanvas(100,100);
QCanvasView *cv=new QCanvasView(c);

QCanvasEllipse *elli=new QCanvasEllipse(50,50,.......,c);
elli->setBrush(Qt::setCyan);
toplayout->addWidget(cv);//can i do this.....

a)how should i add the canvas object in my Qlayout...
b)if not i need an ellipse to show the state of the object red n green...
but making an ellipse using a QPainter object .i cannot add a Qpainter object in Qlayout

Qpainter *p;
toplayout->addWidget(p);//can i do this.....

c)how do i add a nonrectangular widget in layout.

sooner rply
with regards
Amrita

Amrita Singh
25th February 2009, 09:55
hello everyone

i am not able to display the QCanvasEllipse in my Application window.here is the code,can some one find the error.

/////////////...canvas.cpp

#include <qapplication.h>
#include <qcanvas.h>
#include <qnamespace.h>
#include <qlayout.h>
#include"moc_canvas.cpp"
#include<qlayout.h>
int main( int argc, char **argv )
{
QApplication a(argc, argv);
ApplicationWindow * mw = new ApplicationWindow(0,"busmonitor");
mw->resize(1000,700);

mw->show();
a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
return a.exec();

}

ApplicationWindow::ApplicationWindow(QWidget *parent,const char* name)
: QWidget(parent,name)
{

QBoxLayout *topLayout=new QVBoxLayout(this,10);
QBoxLayout *row1 = new QHBoxLayout( topLayout );


QCanvas *testCanvas = new QCanvas(this,"canvas");
testCanvas->resize( 310, 100);
QCanvasEllipse* ce=new QCanvasEllipse(40,40,0*16,360*16,testCanvas);
ce->setX(180);
ce->setY(75);
ce->setBrush( QColor( "red" ) );
QCanvasView canvasView(testCanvas, this,"canvasview");
canvasView.setCanvas(testCanvas);
QVBoxLayout vlay(&mainWidget);
row1->addWidget(&canvasView);
ce.show();

}

ApplicationWindow::~ApplicationWindow()
{
}


////////////////canvas.h..................


#include <qmainwindow.h>


class ApplicationWindow: public QWidget
{
Q_OBJECT

public:
ApplicationWindow(QWidget *parent,const char *name);
~ApplicationWindow();

};

///////////..........

this program compiles without error...n shows only a window....no ellipse

just tryyyyyyyyy..

Amrita