效果如图
Button 对象不能与Web对象属于同一个Widget;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QWidget *w = new QWidget(this);
w->setMinimumSize(50, 50);
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setMargin(10);
QWebEngineView *pWeb = new QWebEngineView;
pWeb->setUrl(QUrl("https://blog.csdn.net/"));
pWeb->show();
pVBoxLayout->addWidget(pWeb);
m_pBtn = new QPushButton(this);
m_pBtn->setFixedSize(50, 50);
m_pBtn->setStyleSheet("background-color:red");
m_pBtn->raise();
m_pBtn->show();
m_pBtn->move(width() - m_pBtn->width() - 30, this->height() - m_pBtn->height() - 30);
w->setLayout(pVBoxLayout);
setCentralWidget(w);
}
void MainWindow::resizeEvent(QResizeEvent *e)
{
e->accept();
m_pBtn->move(width() - m_pBtn->width() - 30, height() - m_pBtn->height() - 30);
}