Closed houssamfarag closed 1 year ago
Please provide minimum code and your environment information
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QMenuBar, QMenu, QStatusBar, QTextEdit, QHBoxLayout, QMdiArea, QMdiSubWindow
from qframelesswindow import FramelessMainWindow, FramelessDialog, FramelessWindow
class MainWindow(FramelessMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Frameless Main Window")
# add menu bar
menuBar = QMenuBar(self.titleBar)
menu = QMenu('File(&F)', self)
menu.addAction('open')
menu.addAction('save')
menuBar.addMenu(menu)
menuBar.addAction('Edit(&E)')
menuBar.addAction('Select(&S)')
menuBar.addAction('Help(&H)', self.showSubWindow)
self.titleBar.layout().insertWidget(0, menuBar, 0, Qt.AlignLeft)
self.titleBar.layout().insertStretch(1, 1)
self.setMenuWidget(self.titleBar)
# add status bar
statusBar = QStatusBar(self)
statusBar.addWidget(QLabel('row 1'))
statusBar.addWidget(QLabel('column 1'))
self.setStatusBar(statusBar)
# set central widget
self.mdi_area = QMdiArea()
self.mdi_area.setOption(QMdiArea.DontMaximizeSubWindowOnActivation)
# self.textEdit = QTextEdit()
self.setCentralWidget(self.mdi_area)
self.setStyleSheet("""
QMenuBar{background: #F0F0F0; padding: 5px 0}
QTextEdit{border: none; font-size: 15px}
QDialog > QLabel{font-size: 15px}
""")
def showSubWindow(self):
# w = QWidget(self)
w = FramelessMainWindow(self)
subwindow_obj = QMdiSubWindow(self)
subwindow_obj.setWidget(w)
self.mdi_area.addSubWindow(subwindow_obj)
subwindow_obj.setContextMenuPolicy(Qt.NoContextMenu)
subwindow_obj.setWindowFlag(Qt.FramelessWindowHint)
subwindow_obj.setMinimumSize(200, 100)
subwindow_obj.show()
# add a label to dialog
# w.setLayout(QHBoxLayout())
# w.layout().addWidget(QLabel('Frameless Dialog'), 0, Qt.AlignCenter)
#
# # raise title bar
# w.titleBar.raise_()
# w.resize(300, 300)
#
# # disable resizing dialog
# w.setResizeEnabled(False)
# w.exec()
if __name__ == '__main__':
# enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QApplication(sys.argv)
# fix issue #50
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)
window = MainWindow()
window.show()
app.exec()
It seems that subwindow in QMdiArea
can't be frameless window.
I have tried it with the main window and it is working great Tried to apply it to mdiArea subwindow it didn't work What should I do ?