Hi...
I've get the example on documentation to put a QTextEdit on a QGraphicsWidget in a QGraphicsScene.
This is the code:
textItem->setReadOnly(true);
textItem->setFont(myFont);
textItem->setTextColor(Qt::black);
textItem->setTextBackgroundColor(Qt::lightGray);
textItem
->setLineWrapMode
(QTextEdit::NoWrap);
QGraphicsWidget *textEdit = addWidget(textItem);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
layout->addItem(textEdit,0,0);
textWidget = new QGraphicsWidget;
textWidget->setLayout(layout);
textWidget->setZValue(10);
addItem(textWidget);
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::Minimum,QSizePolicy::DefaultType);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
layout->addItem(textEdit,0,0);
layout->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum,QSizePolicy::DefaultType);
textWidget = new QGraphicsWidget;
textWidget->setLayout(layout);
textWidget->setZValue(10);
textWidget->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum,QSizePolicy::DefaultType);
addItem(textWidget);
To copy to clipboard, switch view to plain text mode
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.
How can I, in the correct way, make the QGraphicsWidget with the same size of the QTextEdit?
Thanks
Bookmarks