Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:55:59+00:00 2026-05-26T21:55:59+00:00

In the attached example script, why won’t the MyDialog instance show properly when I

  • 0

In the attached example script, why won’t the MyDialog instance show properly when I set MyDialog’s parent to self on line 20 instead of leaving it blank? First I thought the shortcut had stopped working somehow, but obviously that’s not the case.

In this case it doesn’t really make any difference whether the parent is set, but in my real case I need the parent to be set.

Am I missing something obvious here?

import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MyDialog(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setFocusPolicy(Qt.StrongFocus)
        label = QLabel(self)
        label.setText("World")
        hbox = QHBoxLayout()
        hbox.addWidget(label)
        self.setLayout(hbox)

class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.my_dialog = MyDialog()
        #self.my_dialog = MyDialog(self)
        label = QLabel(self)
        label.setText("Hello")
        self.setCentralWidget(label)
        shortcut = QShortcut(QKeySequence(Qt.Key_Tab), self, self.show_my_dialog)
        shortcut.setContext(Qt.ApplicationShortcut)
        self.show()
    def show_my_dialog(self):
        md = self.my_dialog
        if md.isVisible():
            md.hide()
            print 'hide'
        else:
            md.show()
            print 'show'

def main():
    app = QApplication([])
    main_window = MainWindow()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:56:00+00:00Added an answer on May 26, 2026 at 9:56 pm

    On my machine (Kubuntu 11.10) it’s working.
    If Dialog’s parent is None – it opens another frameless window, and i have two entries in taskbar. If i close the main window, dialog remains.

    If you are using Windows – the behavior you described might be related to it. Maybe the window is shown, it’s just behind other windows?

    If Dialog’s parent is the main window – the frameless dialog is shown inside the main window – in the top left corner near the label.

    You might be interested in this info:

    A dialog window is a top-level window mostly used for short-term tasks
    and brief communications with the user. QDialogs may be modal or
    modeless. QDialogs can provide a return value, and they can have
    default buttons. QDialogs can also have a QSizeGrip in their
    lower-right corner, using setSizeGripEnabled().

    Note that QDialog (an
    any other widget that has type Qt::Dialog) uses the parent widget
    slightly differently from other classes in Qt. A dialog is always a
    top-level widget, but if it has a parent, its default location is
    centered on top of the parent’s top-level widget (if it is not
    top-level itself). It will also share the parent’s taskbar entry.

    Use
    the overload of the QWidget::setParent() function to change the
    ownership of a QDialog widget. This function allows you to explicitly
    set the window flags of the reparented widget; using the overloaded
    function will clear the window flags specifying the window-system
    properties for the widget (in particular it will reset the Qt::Dialog
    flag).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote an attached property that I can set on a window to extend
How do I get images in certain fixed size, example I've attached the image
Attached code is an example of how to use Google transliteration feature in certain
For example, the following MXML script attaches a listener to a Button class: <mx:Button
I've encountered an unexpected behavior with threading. I've attached a short example below to
my issue is with flash FLVplakback control with a seekBar attached to it. example
For example, I have a string like this: Line 1 <br/> <br/> Line 2
I've used some neat example's from attached URL's. What I've got so far is
The attached screenshot is from OS X/Firefox 3. Note that the center tab (an
I've created an attached behaviour in my WPF application which lets me handle the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.