English 中文(简体)
为什么当我把他的父母当到场时,我方言正确显示我是如何赢得的?
原标题:Why won t my dialog show properly when I set its parent on instantiation?
  • 时间:2011-11-09 03:04:36
  •  标签:
  • qt
  • pyqt
  • show

在所附的文字中,为什么当我把我的亲子定在第20条线上,而不是留下空白时,我为什么赢得我的原教 instance? 第一,我认为,行凶者已经停止了某种工作,但显然,这并非事实。

在本案中,这并没有真正改变母子是否成立,但在我的真实情况下,我需要确定母子。

我在这里没有明显的东西?

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()
最佳回答

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.

如果你使用Windows,你描述的行为可能与此有关。 窗户是否显示,它只是其他窗户的后面?

如果糖尿病母是主窗——在主窗内显示无线方言——在标签附近的左上角。

http://doc.qt.nokia.com

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).

问题回答

暂无回答




相关问题
Qt: Do events get processed in order?

If I had a class A, where one of its functions does: void A::func() { emit first_signal(); emit second_signal(); } Assuming that a class B has 2 slots, one connected to first_signal, and the ...

How to determine how much free space on a drive in Qt?

I m using Qt and want a platform-independent way of getting the available free disk space. I know in Linux I can use statfs and in Windows I can use GetDiskFreeSpaceEx(). I know boost has a way, ...

Drag & drop with .ui files

I m having big troubles with drag & drop. I ve created a new Qt Designer Form Class in which I have one QListWidget and one QWidget. Now I want to enable dragging & dropping between these two ...

Link errors on Snow Leopard

I creating a small desktop application using Qt and Poco on Mac OS X Snow Leopard. Qt works fine, but once I started linking with Poco I get the following warning: ld: warning: in /Developer/SDKs/...

Showing two windows in Qt4

My friend and I have each created parts of a GUI using Qt 4. They both work independently and I am trying to integrate his form with the my main window. As of now this is the code I am using to try ...

Qt equivalent of .NET data binding?

Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...

热门标签