PDA

View Full Version : QGraphicsScene and QGraphicsView



sabeesh
26th July 2007, 13:27
Hi,

I am using QT 4.2.2. I create a main winodw and in that window I place a tabwidget using QT designer and make the programe and it is working. I need a QGraphicsScence and a QGraphicsView. So add the following code in constructer after the
" setupUi(this); // this sets up GUI "
and Qt create the output.

My problum is that, when I change the tab or QTabWidget then, the QGraphicsView display on the screen. I need that view on the first tab of my QTabWidget. How can I do that?. And also I need to change the line color as red.

Please help me.....

code:
-----------------------

QGraphicsScene *scene1 = new QGraphicsScene(this);
QGraphicsView *view1 = new QGraphicsView(this);
scene1 = new QGraphicsScene(0,0,65,457);
view1->setScene(scene1);
view1->setGeometry(QRect(716, 118, 70, 462));

int x1, y1, x2, y2, t;
x1 = 0; y1=0; x2=100; y2=2, t=0;
//scene->setForegroundBrush(QColor(5, 25, 255, 127));
//scene->setBackgroundBrush(QColor(5, 25, 255, 127));
//QGraphicsLineItem *line = new QGraphicsLineItem( QLineF( 0,0, 100, 2 ) );
QGraphicsLineItem *line;// = new QGraphicsLineItem( QLineF( 0,0, 100, 2 ) );
for ( int a=0; a<100; a++) {
QGraphicsLineItem *line = new QGraphicsLineItem( QLineF( x1,y1, x2, y2 ) );
scene4->addItem(line);
t=x1; x1=x2; x2 = t;
y1= y2; y2= y2+6;
}

--------------------------------------------------------------------

Sabeesh

Gopala Krishna
26th July 2007, 13:30
Replace tabWidget->addTab(view) with tabWidget->insertTab(0,view); to make the view appear in first tab.

To set red color for line use line->setPen(Qt::red)

marcel
26th July 2007, 13:32
First of all, you must add some layouts in the tab widgets.

To answer your problem: start with an empty tab widget.
Use QTabWidget::addTab(view1, "view1"); to create the first tab with the view in it.

That is it.

To change the line color:


line->setPen(QPen(Qt::Red));


Regards

marcel
26th July 2007, 13:33
Replace tabWidget->addTab(view) with tabWidget->insertTab(0,view); to make the view appear in first tab.

To set red color for line use line->setPen(Qt::red)

Where does he call addTab?

Gopala Krishna
26th July 2007, 13:38
Where does he call addTab?

Yup you are right. I thought he was adding the view to the tabWidget in the designer itself. Anyway tabWidget->insertTab(0,view) will always insert the view in first tab. :)

marcel
26th July 2007, 13:47
Yup you are right. I thought he was adding the view to the tabWidget in the designer itself. Anyway tabWidget->insertTab(0,view) will always insert the view in first tab. :)
Of course it will, but he has to remove those two default tabs added by designer, so addTab will work too. :)

Regards

sabeesh
1st August 2007, 05:56
Hi,
I can't solve my problem!!!!!!!!!!!!!
The QTabWidget is designed using the Q.T.4.2.2 and add alos two tabs and these tabs hold some other widget. I want to add the new widget with these widget. Please help me....

Sabeesh

Gopala Krishna
1st August 2007, 06:59
Please go through this qt-designer-manual (http://doc.trolltech.com/4.3/designer-using-a-component.html). This manual explains everything on how to access widgets. :)

Also look at the documentation of QTabWidget.