I am trying to embed a QWidget into a QGraphicsScene using addWidget, and it seems to be embedding successfully, but it is not drawing at all, and I am not sure why. Here's the code where I embed the QWidget:
// JSL
void QWorksheetDoc::addTable(DrawObjData *data, bool front, bool leaveSelected, char *theText)
{
if (worksheetView)
{
worksheetScene->clearSelection();
QDatatable *table = new QDatatable();
table->QDatatable::IDatatable(this);
QGraphicsProxyWidget *theProxy = worksheetView->scene()->addWidget(table);
// JSL - install the common scene Event filter object.
theProxy->installSceneEventFilter(sceneDrawCommon);
theProxy->setSelected(true);
if (front)
bringToFront();
if (leaveSelected == false)
worksheetScene->clearSelection();
worksheetView->show();
}
}
// JSL
void QWorksheetDoc::addTable(DrawObjData *data, bool front, bool leaveSelected, char *theText)
{
if (worksheetView)
{
worksheetScene->clearSelection();
QDatatable *table = new QDatatable();
table->QDatatable::IDatatable(this);
QGraphicsProxyWidget *theProxy = worksheetView->scene()->addWidget(table);
theProxy->setFlag(QGraphicsItem::ItemIsMovable);
theProxy->setFlag(QGraphicsItem::ItemIsSelectable);
// JSL - install the common scene Event filter object.
theProxy->installSceneEventFilter(sceneDrawCommon);
theProxy->setSelected(true);
if (front)
bringToFront();
if (leaveSelected == false)
worksheetScene->clearSelection();
worksheetView->show();
}
}
To copy to clipboard, switch view to plain text mode
QDatatable descends from QTableView.
Here's the code where QDatatable paints. I added the frame, and the fill to try to see anything on the screen:
//
// JSL - paint
//
{
//QRectF rect = frameRect();
painter.
setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::darkGray);
painter.drawRect(rect());
painter.
fillRect(rect
(),
QColor(224,
424,
224));
}
//
// JSL - paint
//
void QDatatable::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
//QRectF rect = frameRect();
QTableView::paintEvent(event);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::darkGray);
painter.drawRect(rect());
painter.fillRect(rect(), QColor(224,424,224));
}
To copy to clipboard, switch view to plain text mode
If anyone has any idea why this is not working I would appreciate hearing about it. What I see is a white rectangle that seems to obey z ordering, but is not selectable, or movable, and doesn't render anything.
Bookmarks