title: Qt QGraphicsView: Displaying QGraphicsView inside a tab
body: <p>I will describe my issue.</p>
  
  <p>I have a class for tab, which looks approximately like this:</p>
  
  <pre><code>class Tab : public QWidget
  {
  public:
    Tab();
     ...
  private:
     ...
    QGraphicsView *view;
     ...
  };
  </code></pre>
  
  <p>In <code>Tab()</code> I create the <code>view</code>. Now in my main window I would like to have a <code>QTabWidget</code>, which contains some tabs, where each tab displays a <code>QGraphicsView</code>. It looks approximately like this:</p>
  
  <pre><code>class MainWindow : QMainWindow
  {
  public:
    MainWindow();
     ...
  private:
     ...
    QTabWidget *tabWidget;
     ...
  };
  </code></pre>
  
  <p>and</p>
  
  <pre><code>MainWindow::MainWindow()
  {
    tabWidget = new QTabWidget(this);
    tabWidget-&gt;addTab(new Tab, tr("tab 1"));
    tabWidget-&gt;addTab(new Tab, tr("tab 2"));
  
    setCentralWidget(tabWidget);
  }
  </code></pre>
  
  <p>This doesn't display the <code>QGraphicsView</code>s in the tabs. To make the <code>QGraphicsView</code>s visible, I would have to write something like this:</p>
  
  <pre><code>MainWindow::MainWindow()
  {
    tabWidget = new QTabWidget(this);
    tab1 = new Tab;
    tab2 = new Tab;
    tabWidget-&gt;addTab(tab1-&gt;view, tr("tab 1"));
    tabWidget-&gt;addTab(tab2-&gt;view, tr("tab 2"));
  
    setCentralWidget(tabWidget);
  }
  </code></pre>
  
  <p>and <code>view</code> would have to be public in the class <code>Tab</code>, which really looks bad. The class <code>Tab</code> has some private functions, which are used to construct <code>view</code> and I don't want <code>view</code> to be public in <code>Tab</code>.</p>
  
  <p>How to get around this?</p>
  
  <p>I was thinking of creating a class, which inherits from <code>QGraphicsView</code> and adding my own functions, but I'm not quite sure how to do this so that it works for me.</p>
  
  <p>Thank you for your answers and comments.</p>