title: Custom Titlebar with frame in PyQt5
body: <p>I'm working on an opensource markdown supported minimal note taking application for Windows/Linux. I'm trying to remove the title bar and add my own buttons. I want something like, a title bar with only two custom buttons as shown in the figure<a href="https://i.stack.imgur.com/iPObM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/iPObM.png" alt="enter image description here"></a></p>
  
  <p>Currently I have this:</p>
  
  <p><a href="https://i.stack.imgur.com/uzFOI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/uzFOI.png" alt="enter image description here"></a></p>
  
  <p>I've tried modifying the window flags: </p>
  
  <ul>
  <li>With not window flags, the window is both re-sizable and movable. But no custom buttons.</li>
  <li>Using <code>self.setWindowFlags(QtCore.Qt.FramelessWindowHint)</code>, the window has no borders, but cant move or resize the window</li>
  <li>Using <code>self.setWindowFlags(QtCore.Qt.CustomizeWindowHint)</code>, the window is resizable but cannot move and also cant get rid of the white part at the top of the window.</li>
  </ul>
  
  <p>Any help appreciated. You can find the project on GitHub <a href="https://github.com/PraveenKishore/Simple.io/" rel="noreferrer">here</a>.</p>
  
  <p>Thanks..</p>
  
  <p><strong>This is my python code:</strong></p>
  
  <pre><code>from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets, uic
  import sys
  import os
  import markdown2 # https://github.com/trentm/python-markdown2
  from PyQt5.QtCore import QRect
  from PyQt5.QtGui import QFont
  
  simpleUiForm = uic.loadUiType("Simple.ui")[0]
  
  class SimpleWindow(QtWidgets.QMainWindow, simpleUiForm):
      def __init__(self, parent=None):
          QtWidgets.QMainWindow.__init__(self, parent)
          self.setupUi(self)
          self.markdown = markdown2.Markdown()
          self.css = open(os.path.join("css", "default.css")).read()
          self.editNote.setPlainText("")
          #self.noteView = QtWebEngineWidgets.QWebEngineView(self)
          self.installEventFilter(self)
          self.displayNote.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
          #self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
  
      def eventFilter(self, object, event):
          if event.type() == QtCore.QEvent.WindowActivate:
              print("widget window has gained focus")
              self.editNote.show()
              self.displayNote.hide()
          elif event.type() == QtCore.QEvent.WindowDeactivate:
              print("widget window has lost focus")
              note = self.editNote.toPlainText()
              htmlNote = self.getStyledPage(note)
              # print(note)
              self.editNote.hide()
              self.displayNote.show()
              # print(htmlNote)
              self.displayNote.setHtml(htmlNote)
          elif event.type() == QtCore.QEvent.FocusIn:
              print("widget has gained keyboard focus")
          elif event.type() == QtCore.QEvent.FocusOut:
              print("widget has lost keyboard focus")
          return False
  </code></pre>
  
  <p>The UI file is created in the following hierarchy</p>
  
  <p><a href="https://i.stack.imgur.com/jzFq1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jzFq1.png" alt="enter image description here"></a></p>