2

I'm adding the discord widget from widgetbot to a grid layout in a way it can expand above other widgets, the problem is, even when the widget is 'closed' the QWebEngineView widget occupies the entire area blocking things below it to be clicked:

enter image description here

I thought of setting a maximum size to the widget when it is opened and another when it's closed so it doesn't overlay other widgets when it's not 'opened'.

I tried installing an event filter but it didn't throw any event when the widget is opened/closed, would like to ask what other way I could detect it?


#include "discordwidget.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    auto wdgt = new DiscordWidget(this);
}

//discordwidget.h
#include <QtWebEngineWidgets>

class DiscordWidget : public QWebEngineView 
{
    Q_OBJECT

public:

    DiscordWidget(QWidget* parent = 0) : QWebEngineView(parent)
    {    
        this->page()->setBackgroundColor(Qt::transparent);   
        
        // Tutorial: https://docs.widgetbot.io/embed/crate/tutorial/#getting-started
        this->page()->setHtml(R"(    
            <script src='https://cdn.jsdelivr.net/npm/@widgetbot/crate@3' async defer>
            new Crate({
                server: '', // Replace with your discord server
                channel: '' // ... channel
            })
            </script>    
        )");

        this->installEventFilter(this);
        this->page()->installEventFilter(this);    
    } 

    bool eventFilter(QObject *obj, QEvent *e)
    {
        qDebug() << e->type();

        if( e->type() == QEvent::ChildAdded )
        {
            QChildEvent *ce = static_cast<QChildEvent*>(e);
            ce->child()->installEventFilter(this);
        }
        return false;
    }    
};
5
  • Maybe use width and height from here docs.widgetbot.io/embed/react-embed/props/#props Commented Dec 7, 2022 at 8:19
  • @ניר it would result in the same thing, I need to know when the widget is opened/closed to set the widget width according. Commented Dec 7, 2022 at 18:23
  • Maybe wrap the button with transparent QWidget and propogate the mouse events? Commented Dec 7, 2022 at 19:08
  • Or hook to some javascript event stackoverflow.com/questions/61764733/… Commented Dec 8, 2022 at 5:59
  • @ניר i couldn't get this working, i didnt get any message, what about you? Commented Dec 8, 2022 at 18:36

1 Answer 1

0

I stuck with the problem myself and, I guess, there are no beautiful solutions.

Based on this answer: QWebEngineView, like QWidget itself, does not have any signals on closing. So, you may want to implement it yourself:

class YourWindow : public QWebEngineView
{
    Q_OBJECT
public:
    explicit YourWindow(QWidget *parent = nullptr) : QWebEngineView{parent} { }
protected:
    void closeEvent(QCloseEvent *event) override {
        QWebEngineView::closeEvent(event);
        emit this->YourWindowClosed();
}
signals:
    void YourWindowClosed();
};

Further, you can connect your signal to any slot that fits your purpose:

YourWindow* View = new YourWindow();
QObject* Foo = new QObject();
connect(View, SIGNAL(LoginWindowClosed()), Foo, SLOT(AnySlotYouNeed()));

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.