VS+QT开发Ocx/ActiveX控件-------网页中全屏 二
ActiveX组件窗口设计为两层,底层固定在HTML的窗口上,顶层用来全屏。
具体操作为:
全屏时将顶层弹出,即topwidget->setParent(nullptr);
退出全屏时再将顶层topwidget->setParent(parent);
这样就能恢复回来。
为了能随窗口大小变化,需要底层需要设置一个layout,这个layout包含顶层。
每次全屏/退出全屏都需要重新设置一下QGridLayout
如下:
delete ui.bottomWidget->layout();
QGridLayout*m_gridLayout = new QGridLayout;
m_gridLayout->addWidget(topwidget, 0, 0);
m_gridLayout->setSpacing(0);
m_gridLayout->setContentsMargins(0, 0, 0, 0);
ui.bottomWidget->setLayout(m_gridLayout);
出现问题如下:(QGridLayout顶部超出范围)
解决: QTimer设置延时设置QGridLayout
原因: 可能QGridLayout在生效的时候,父widget的宽高还不是最后的宽高
m_pTimer = new QTimer;
topwidget= new QWidget;
m_pTimer->setInterval(100);
m_pTimer->start();
connect(m_pTimer, &QTimer::timeout, [=]()
{
QGridLayout*gridLayout = new QGridLayout;
gridLayout->addWidget(topwidget, 0, 0);
gridLayout->setSpacing(1);
gridLayout->setContentsMargins(0, 0, 0, 0);
ui.widget->setLayout(gridLayout);
m_pTimer->stop();
});
正常如下所示: