paolom
7th October 2009, 10:21
Hi...
I've get the example on documentation to put a QTextEdit on a QGraphicsWidget in a QGraphicsScene.
This is the code:
textItem=new QTextEdit;
textItem->setReadOnly(true);
textItem->setFont(myFont);
textItem->setTextColor(Qt::black);
textItem->setTextBackgroundColor(Qt::lightGray);
textItem->setLineWrapMode(QTextEdit::NoWrap);
QGraphicsWidget *textEdit = addWidget(textItem);
textEdit->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Mi nimum,QSizePolicy::DefaultType);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
layout->addItem(textEdit,0,0);
layout->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Mi nimum,QSizePolicy::DefaultType);
textWidget = new QGraphicsWidget;
textWidget->setLayout(layout);
textWidget->setZValue(10);
textWidget->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Mi nimum,QSizePolicy::DefaultType);
addItem(textWidget);
where textEdit is a QTextEdit* and textWidget is a QTextWidget*.
After I set the text on the textItem with setPlainText(QString).
It works correctly but the problem is that when I show on the scene (the class where this method runs) the widget is larger then the QTextEdit, as shown in the picture.
http://www.agritur-aso.it/immagini/widget.png
How can I, in the correct way, make the QGraphicsWidget with the same size of the QTextEdit?
Thanks
I've get the example on documentation to put a QTextEdit on a QGraphicsWidget in a QGraphicsScene.
This is the code:
textItem=new QTextEdit;
textItem->setReadOnly(true);
textItem->setFont(myFont);
textItem->setTextColor(Qt::black);
textItem->setTextBackgroundColor(Qt::lightGray);
textItem->setLineWrapMode(QTextEdit::NoWrap);
QGraphicsWidget *textEdit = addWidget(textItem);
textEdit->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Mi nimum,QSizePolicy::DefaultType);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
layout->addItem(textEdit,0,0);
layout->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Mi nimum,QSizePolicy::DefaultType);
textWidget = new QGraphicsWidget;
textWidget->setLayout(layout);
textWidget->setZValue(10);
textWidget->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Mi nimum,QSizePolicy::DefaultType);
addItem(textWidget);
where textEdit is a QTextEdit* and textWidget is a QTextWidget*.
After I set the text on the textItem with setPlainText(QString).
It works correctly but the problem is that when I show on the scene (the class where this method runs) the widget is larger then the QTextEdit, as shown in the picture.
http://www.agritur-aso.it/immagini/widget.png
How can I, in the correct way, make the QGraphicsWidget with the same size of the QTextEdit?
Thanks