Mikhail
Mikhail

Reputation: 8038

Paradigmatic sizeHint() from QWidget::createWindowContainer?

So, I wrapped a custom QWindow in a widget using createWindowContainer. By default this gives a invalid size hint (-1) because the QWindow isn't in a layout. Furthermore, QWindow doesn't have a size hint.

How can I specify the sizeHint() using a function in render_surface?

window_container = QWidget::createWindowContainer(render_surface);
auto hint = window_container->sizeHint(); // how do I specify this?
std::cout << hint.width() << std::endl;  //invalid

Upvotes: 3

Views: 678

Answers (2)

Mikhail
Mikhail

Reputation: 8038

I posted something on the bug tracker, the current method is to use a second widget to "shadow" the size.

The code looks something like:

In the parent's constructor

auto window_container = QWidget::createWindowContainer(render_surface);
window_container->setLayout(new QGridLayout());
fml = new PlaceHolderWidget;
window_container->layout()->addWidget(fml);

In the parent's resize event

void RenderContainer::resizeEvent(QResizeEvent *event)
{
    auto frame_size = render_surface->img_size;
    if (frame_size.n() > 0)
    {
      ...
      fml->setSizeHint(QSize(predicted_width, predicted_height));
    }
    QWidget::resizeEvent(event);
}

Where PlaceHolderWidget overrides sizeHint(). https://bugreports.qt.io/browse/QTBUG-57693

Upvotes: 0

Adrian Colomitchi
Adrian Colomitchi

Reputation: 3992

Overwrite virtual const QSize& sizeHint() const method to the wrapper, method which simply returns QWindow::size() of its wrapped window.

Upvotes: 0

Related Questions