pythonpysidepyside6qinputdialog

Qt.FramelessWindowHint not working on QInputDialog


I'm learning PySide6 and I'm trying to create a frameless QInputDialog.

When I set:

from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QInputDialog, QMainWindow


app = QApplication()

input_dialog = QInputDialog(flags=Qt.FramelessWindowHint)
text, ok = input_dialog.getText(QMainWindow(), 'input dialog', 'Is this ok?')
if ok:
    print(text)

app.exec()

the frame still appears. Why?

enter image description here


Solution

  • The getText method is static so input_dialog is not the displayed window but an instance of QInputDialog is created internally, so you must pass the flags through the method:

    from PySide6.QtCore import Qt
    from PySide6.QtWidgets import QApplication, QInputDialog
    
    app = QApplication()
    
    text, ok = QInputDialog.getText(
        None, "input dialog", "Is this ok?", flags=Qt.FramelessWindowHint
    )
    if ok:
        print(text)