Qt 带有自己的子窗口小部件(按钮)和背景图像的QWidget不工作

Qt 带有自己的子窗口小部件(按钮)和背景图像的QWidget不工作,qt,qt5,Qt,Qt5,我想在Qt中实现一个窗口,它具有 我从一张QImage中为自己绘制的背景图像 处于绝对位置的普通小部件(QPushButton) 这就是我的代码: // the constructor ReplayWidget::ReplayWidget(QWidget *parent) :QWidget(parent, Qt::WindowStaysOnTopHint) { m_closeButton = new QPushButton(parent); m_clos

我想在Qt中实现一个窗口,它具有

  • 我从一张QImage中为自己绘制的背景图像
  • 处于绝对位置的普通小部件(QPushButton)
这就是我的代码:

// the constructor
ReplayWidget::ReplayWidget(QWidget *parent)
             :QWidget(parent, Qt::WindowStaysOnTopHint)
{
   m_closeButton = new QPushButton(parent);
   m_closeButton->setText("Close");
   m_closeButton->move(10, 10);
   m_closeButton->setMinimumSize(QSize(100, 51));
   m_closeButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
}

// the overwritten repaint-method
void ReplayWidget::paintEvent(QPaintEvent* pe)
{
   QPainter painter(this);

   if (m_bgImage)
   {
      painter.drawImage(QPoint(0, 0), *m_bgImage);
   }
   QWidget::paintEvent(pe);
}
不幸的是,这不起作用,来自m_bgImage的图像按预期显示,但按钮不可见


你知道这里有什么问题吗?

添加
m_closeButton->show()
并将
QPushButton(父项)
替换为
QPushButton(此)
@mugiseyebrows是的,就是这样-谢谢!:-)请将评论转换为答案,并勾选为已解决。