mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-28 02:21:25 +00:00
ui/obs-browser-widget: Fix strange layout issue in Qt6
When a QCefWidget is alone and all by itself, no layout updates are performed on the "window". This causes a problem where it just stays in place, instead of moving with the rest of the elements. The fix to this appears to be to just add a different Qt widget into the layout. Looks stupid, is stupid, but works anyway. Qt is weird.
This commit is contained in:
parent
3187a165ba
commit
5a58aa8a6b
2 changed files with 18 additions and 13 deletions
|
@ -13,6 +13,9 @@
|
|||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include "warning-enable.hpp"
|
||||
|
||||
streamfx::ui::obs_browser_cef::obs_browser_cef()
|
||||
|
@ -70,23 +73,28 @@ std::shared_ptr<streamfx::ui::obs_browser_cef> streamfx::ui::obs_browser_cef::in
|
|||
|
||||
streamfx::ui::obs_browser_widget::obs_browser_widget(QUrl url, QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
// Create Layout
|
||||
auto layout = new QGridLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
// Create CEF Widget
|
||||
_cef = obs_browser_cef::instance();
|
||||
_widget = reinterpret_cast<QCef*>(_cef->cef())
|
||||
->create_widget(this, url.toString().toStdString(),
|
||||
reinterpret_cast<QCefCookieManager*>(_cef->cookie_manager()));
|
||||
if (!_widget) {
|
||||
throw std::runtime_error("Failed to create QCefWidget.");
|
||||
throw std::runtime_error("Failed to create CEF Widget.");
|
||||
}
|
||||
|
||||
// Add a proper layout.
|
||||
_layout = new QHBoxLayout();
|
||||
_layout->setContentsMargins(0, 0, 0, 0);
|
||||
_layout->setSpacing(0);
|
||||
this->setLayout(_layout);
|
||||
_layout->addWidget(_widget);
|
||||
|
||||
// Disable all popups.
|
||||
dynamic_cast<QCefWidget*>(_widget)->allowAllPopups(false);
|
||||
_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
layout->addWidget(_widget, 0, 0);
|
||||
|
||||
// This fixes a strange issue where Qt just does not update the size of the QCefWidget.
|
||||
// I do not know why this is, all I know is that this is absolutely necessary for QCefWidget.
|
||||
auto test = new QWidget(this);
|
||||
test->setFixedSize(0, 0);
|
||||
layout->addWidget(test, 1, 0);
|
||||
}
|
||||
|
||||
streamfx::ui::obs_browser_widget::~obs_browser_widget() {}
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
#include "util/util-library.hpp"
|
||||
|
||||
#include "warning-disable.hpp"
|
||||
#include <QHBoxLayout>
|
||||
#include <QSharedPointer>
|
||||
#include <QUrl>
|
||||
#include <QWidget>
|
||||
#include "warning-enable.hpp"
|
||||
|
@ -38,7 +36,6 @@ namespace streamfx::ui {
|
|||
|
||||
std::shared_ptr<obs_browser_cef> _cef;
|
||||
QWidget* _widget;
|
||||
QHBoxLayout* _layout;
|
||||
|
||||
public:
|
||||
obs_browser_widget(QUrl url, QWidget* parent = nullptr);
|
||||
|
|
Loading…
Reference in a new issue