title: call paintevent on my own in other class in qt c++
body: <p>I am new to qt and am doing a Red black tree visualization using qt c++. i have created node structure using Qpaint and im ready with basic data structure tree code, the only problem is the updation of paint event coz i want to call paint event whenever I want too.</p>
  
  <p>and also while painting my initial nodes are disappearing . please go through the code and help.</p>
  
  <p>code is: </p>
  
  <pre><code>//dispaymenu.cpp
  
  #include "displaymenu.h"
  #include "ui_displaymenu.h"
  #include "datastruct.cpp"
  #include&lt;QtCore&gt;
  #include&lt;QtGui&gt;
  
  DisplayMenu::DisplayMenu(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::DisplayMenu)
  {
      ui-&gt;setupUi(this);
  
  }
  DisplayMenu::~DisplayMenu()
  {
      delete ui;
  }
  void DisplayMenu::paintEvent(QPaintEvent *)
  {
          createNode(text,col);
  }
  
  void DisplayMenu::createNode(QString text,char col)
  {
  
      QRectF rect(x,y,80,80);    //create rectangle object which is not seen
      QPainter p(this);
      if(col=='b')
          p.setBrush(Qt::black);
      else if(col=='r')
          p.setBrush(Qt::red);
      p.drawEllipse(rect);        //circle fits into the rect passed
      p.setPen(Qt::white);
      p.setFont(QFont("Arial", 15));      //to set font and size of text
      p.drawText(rect, Qt::AlignCenter,text);
  }
  
  void DisplayMenu::setText()
  {
      bool ok;
      text = QInputDialog::getText(this, tr("getText()"),
                                           tr("getdata:"), QLineEdit::Normal,
                                           QDir::home().dirName(), &amp;ok);
      if (ok &amp;&amp; !text.isEmpty())
      {
          int ele=text.toInt();
          RBTree t1(a);
          col=t1.insert(ele);
          a=1;
          createNode(text,col);
      }
  }
  
  
  void DisplayMenu::on_textButton_clicked()
  {
      setText();
  }
  
  this was our mainwindow file.
  
  //main.cpp
  #include "displaymenu.h"
  #include &lt;QApplication&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      displaymenu w;
      w.show();
  
      return a.exec();
  }
  
  
  //datastruct.cpp
  
  #include &lt;bits/stdc++.h&gt;
  #include&lt;datastruct.h&gt;
  #include&lt;displaymenu.h&gt;
  #include"displaymenu.cpp"
  
  
  using namespace std;
  
  enum Color {RED, BLACK};
  
  struct Node
  {
      int data;
      char color;
      Node *left, *right, *parent;
  
      // Constructor
      Node(int data)
      {
          this-&gt;data = data;
          this-&gt;color='r';
          left = right = parent =nullptr;
      }
  };
  
  // Class to represent Red-Black Tree
  class RBTree
  {
  public:
      Node *root;
      void rotateLeft(Node *&amp;, Node *&amp;);
      void rotateRight(Node *&amp;, Node *&amp;);
      void fixViolation(Node *&amp;, Node *&amp;);
  
  
      // Constructor
      RBTree(int a)
      {
          if(a==0)
              root = nullptr;
      }
      char insert(int ele);
      //void inorder();
      //void levelOrder();
  };
  Node* BSTInsert(Node* root, Node *pt)
  {
      //DisplayMenu d(&amp;p);
      /* If the tree is empty, return a new node */
      if (root == nullptr)
      {
          pt-&gt;color='b';
          return pt;
      }
  
  
      /* Otherwise, recur down the tree */
      if (pt-&gt;data &lt; root-&gt;data)
      {
          root-&gt;left = BSTInsert(root-&gt;left, pt);
          root-&gt;left-&gt;parent = root;
      }
      else if (pt-&gt;data &gt; root-&gt;data)
      {
          root-&gt;right = BSTInsert(root-&gt;right, pt);
          root-&gt;right-&gt;parent = root;
      }
  
      /* return the (unchanged) node pointer */
      return root;
  }
  char RBTree::insert(int data)
  {
      Node *pt = new Node(data);
  
      // Do a normal BST insert
      root=BSTInsert(root, pt);
      return pt-&gt;color;
  
      // fix Red Black Tree violations
      //fixViolation(root, pt);
  }
  </code></pre>