OpenBoard-org / OpenBoard

OpenBoard is a cross-platform interactive whiteboard application intended for use in a classroom setting.
https://openboard.ch/
GNU General Public License v3.0
2.33k stars 420 forks source link

Widget on board #254

Closed torinfo closed 4 years ago

torinfo commented 4 years ago

Hi,

I am still trying to understand the code.

I am trying to add a new tool to the Stylus panel. The new tool should display a widget on the board, and after some actions should replace itself with a UBGraphicsTextItem.

I can add a widget without issues directly in UBGraphicsScene without a problem.

Now, I would like to leverage the UBGrahicsProxyWidget and have crated a new derived class based on that widget, because it will give me a nice frame and all the hooks to manipulate the widget.

Everything seems fins, but the widget itself does not display. I can't see it. It seems to have the correct sizes and the correct position, but I cannot see it, let alone that it receives mouse events.

Does anyone have any idea what could be the cause of this?

I have OpenBoard up and running on Qt 5.13.1 (On Windows) using QtWebKit and VS2017 32 bit.

Would it be worthwhile to try this (opening a widget in a class derived from UBGraphicsProxyWidget) on Qt5.5?

I just don't understand why the widget is not showing.

torinfo commented 4 years ago

I just tried the same thing on a Qt5.5 VS2013 version and that doesn't make a difference.

The frame appears as expected, but the widget itself doesn't show. It says it's visible, and the positions and size is correct.

If I create a QWidget, and a plain vanilla QGraphicsProxyWidget, and add the widget to the QGraphicsProxyWidget and then the QGraphicsProxyWidget to the UBGraphicsScene, the widget shows. So it has somehow to do with the base class UBGraphicsProxyWidget, or the delegate handling, but I don't see anything obvious that would cause this behaviour.

It might have something to do with the layering, but again, I don't understand how.

kaamui commented 4 years ago

Hello,

UBGraphicsProxyWidget is no longer used. It comes from Open-Sankoré and could simply be removed from OpenBoard sources. I think I introduced an abstraction of UBGraphicsProxWidget in Open-Sankoré, but if I remember well it was mostly to workaround a QT-BUG (qt4.8), where clicking on widget attached to the scene would sometimes return the QGraphicsProxWidget instead of the widget itself.

Not sure if it could help you, but you might find some useful example of how it's used on Sankoré

https://github.com/Sankore/Sankore-3.1/blob/master/src/domain/UBAbstractGraphicsProxyWidget.h https://github.com/Sankore/Sankore-3.1/blob/master/src/domain/UBAbstractGraphicsProxyWidget.cpp https://github.com/Sankore/Sankore-3.1/blob/master/src/domain/UBGraphicsProxyWidget.h https://github.com/Sankore/Sankore-3.1/blob/master/src/domain/UBGraphicsProxyWidget.cpp https://github.com/Sankore/Sankore-3.1/blob/master/src/domain/UBGraphicsScene.h https://github.com/Sankore/Sankore-3.1/blob/master/src/domain/UBGraphicsScene.cpp

UBGraphicsProxyWidget* UBGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags)
{
    UBGraphicsProxyWidget *proxy = new UBGraphicsProxyWidget(0, wFlags);
    proxy->setWidget(widget);
    QGraphicsScene::addItem(proxy);
    return proxy;
}

Hope it helps.

torinfo commented 4 years ago

@kaamui Thank you. I'll have a look. For now I resolved it in a completely different way by creating a widget parented by UBBoardView, but I will revisit this in the near future.