c ++ – Correct use of your own widget with layouts

I have created a widget own; a numeric keypad In the initial tests, it works and displays correctly.

The header, numkeypad.hpp:

#include 
#include 

class NumKeypad: public QWidget {
  Q_OBJECT

  QGridLayout m_layout;
  QPushButton m_buttons[12];

public:
  NumKeypad (QWidget * parent = nullptr): QWidget (parent) {
    for (int idx = 0; idx <12; ++ idx) {
      m_buttons[idx].setSizePolicy (QSizePolicy (QSizePolicy :: Ignored, QSizePolicy :: Ignored));
      m_layout.addWidget (& (m_buttons[idx] ), idx / 3, idx% 3);
    }

    setLayout (& m_layout);
  }
};

And the code, main.cpp:

#include "numkeypad.hpp"

#include 
#include 

int main (int argc, char ** argv) {
  QApplication app (argc, argv);
  QMainWindow mw;

  mw.setCentralWidget (new NumKeypad (& mw));

  mw.setWindowTitle ("If it works");
  mw.show ();

  app.exec ();
}

It shows what I expect, a keypad:

enter the description of the image here

This is not very useful. The idea is to be able to include it in several windows, as necessary. For the first test, I add another file: widget.hpp:

#include "numkeypad.hpp"

#include 
#include 
#include 

class Widget: public QWidget {
  Q_OBJECT;

  QVBoxLayout m_vlayout;
  QHBoxLayout m_hlayout;
  QListWidget m_left;
  QListWidget m_right;
  NumKeypad m_keypad;

public:
  Widget (QWidget * parent = nullptr): QWidget (parent) {
    m_vlayout.addWidget (& m_right);
    m_vlayout.addWidget (& m_keypad);

    m_hlayout.addWidget (& m_left);
    m_hlayout.addLayout (& m_vlayout);

    setLayout (& m_hlayout);
  }
};

And I modify the main.cpp:

#include "widget.hpp"

#include 
#include 

int main (int argc, char ** argv) {
  QApplication app (argc, argv);
  QMainWindow mw;

  mw.setCentralWidget (new Widget (& mw));
  mw.show ();

  app.exec ();

  return 0;
}

I wait for a pretty window, with several lists, and a keypad in the lower right corner. However, I get this: a beautiful Empty space:

enter the description of the image here

  1. Where is my keypad ? Because it does not show up ?

  2. How do I solve it ?