Can you display a QDialog as the central widget of a QMainWindow in Python? If so, how would you do it? I am trying to find the easiest way to add a menu bar which is only available with QMainWindow to my understanding. Is it possible to connect the two together?
QDialog as central widget layout in QMainWindow
525 Views Asked by HoneyWeGOTissues At
1
There are 1 best solutions below
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in PYQT5
- Unresolved attribute reference 'setModel' for class 'Dialog'
- Stopwatch controlled by 4 buttons
- PyQT5 doesn't prompt to overwrite when a default suffix is used
- I am encountering issues on making a custom file browser with PyQt5 using QTreeView, QStandardItemModel and QStandardItem: my program randomly crashes
- displaying several treeviews one below the other
- PyQt5 heading and subheading
- How can I run "least cost path" algorithm in a standalone script in python (using qgis and PyQt5 package) or in python console of QGIS?
- MITMProxy with GUI
- PyInstaller with PyQt5 Generates "DLL load failed" Error for QtPrintSupport
- PyQT6 setWindowFlags issue
- Many QPushButtons clicked connecting using exec()
- ImportError: DLL load failed while importing QtWebChannel
- PyCharm & Python: Reboot PyQt5 Application
- How do I ensure closing of database connection using PyQt5.QtSql?
- PyQt5 slow load label
Related Questions in QMAINWINDOW
- PySide6 runs code without issues but nothing appears
- QMainWindow not found
- Add a Vertical QToolBar to the bottom of QMainWindow
- How to put an icon to the left side of a QMenuBar and a QToolBar?
- How To Make a QTreeView Object Resize to Match the Main Window?
- Removing Extra Space Around QTabWidget in a QMainWindow Layout in PySide2
- QWebEngineView closes immediately after loading
- Unable to keep searching on QplainTextEdit while Qdialog is open
- Qt/C++ – How to differentiate between closing main window from an external app and clicking close button click from title bar?
- When I used a custom Widget as the CentralWidget for QMainWindow in PyQt6, there was a gap between the CentralWidget and the QMainWindow
- QLabel text doesn't update after i changed it when QMainWindow is shown
- How can I emit a signal from QMainWindow to QThread in PyQt5?
- Qt: Show MainWindow in main.cpp without using QT Designer
- How can QPixmaps get auto-resized in PyQt6 when the Mainwindow is resized?
- pyqt6 change font size on MainWindow resize
Related Questions in QDIALOG
- QDialog with WindowModal modality looses the WindwoTitle on Mac
- Disable esc key from closing QDialog
- How to pass custom class (subclass of QDialog) to other custom class (subclass of QObject) in Qt5?
- Close QDialog window on button click PyQt5
- Unable to keep searching on QplainTextEdit while Qdialog is open
- Main Gui Thread Freezes after using a QDialog with Exec_()
- How to remove 'current' widget so that def can be used as a Global Variable
- Creating multiple tabs inside of a preset layout and keeping data within them. -- PyQT5 within KLayout API
- Custom modeless dialog not showing
- Get value of input fields using PySide2
- PyQt Can't open 3d dialog window and close the 1st one
- Why does loading Freecad UI in new, "empty" document generate the error - : Active task dialog found
- Connect QPushButton in the QDialog in one header file with method in another header file
- How can i set and then get a specific indentifier for a QDialog window when i create it
- Closing a QDialog window that has been opened by another widget
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
tl;dr
No, but you can add a menubar to a layout set for the QDialog, using
setMenuBar()or even by adding the menubar as you would do for any other widget, just by doing that on "top" of that layout.Is it possible?
The technical answer is "yes": since QDialog is a QWidget, you can just use
setCentralWidget()as you would do with any other QWidget subclass.The real answer is "NO: don't do it!".
QDialog, just like QMainWindow, is intended to be a top level widget (aka, a "window"), so it should never be added as a child of a widget or in its layout.
There are very few exceptions to that:
Most importantly, QDialog has specific flags and event filters that might be problematic.
For instance, take this simple example:
Now, just press Esc, and you'll see that the dialog disappears.
The same happens by adding a QDialog as a child of any widget, clearly meaning that it should never be done (unless when using the "container" systems listed above).
This is one of the many reasons for which some tutorials on YouTube should be completely disregarded (since they provide terrible suggestions, like adding a QMainWindow or QDialog to a QStackedWidget).
The solution
Actually, it's very simple: just add the menubar to the top level layout of the dialog, just like you would do for any other widget.
Besides, consider that all Qt layout managers inherit from QLayout, which has a very basic and important function that is often ignored:
setMenuBar().Note that this is actually a "convenience" feature, and it only works for the "top level" layout: if you add the menubar to a nested layout, it won't be considered in the whole size hint/policy computation, and it will be probably shown above (in the
zstacking level) any other widget near it.Also note that, for obvious reasons, this cannot be done from Designer. If you have a QDialog created in Designer and you want to add a menubar, you have to do it by code.
Assuming that you properly set a top level layout (as you should always do) for your dialog in Designer: