确定Equals()是否为覆盖?(Determine if Equals() is an override?)
我有一个Type(type)的实例。 如何确定它是否覆盖Equals()?
I have an instance of Type (type). How can I determine if it overrides Equals()?
原文:https://stackoverflow.com/questions/3629605
最满意答案
您的代码的主要问题是您为
StartQT4
子类使用了错误的基类。 它应该与Qt Designer中的顶级类匹配,后者是QDialog
。您还可以通过将ui直接添加到子类,以及使用新式信号和插槽语法来简化代码。
有了这些更改,您的代码将如下所示:
import sys from PyQt4 import QtCore, QtGui from simpleTextEditor_gui import Ui_simpleTextEditor class StartQT4(QtGui.QDialog, Ui_simpleTextEditor): def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setupUi(self) # tutaj dajemy wlasne polaczenia slotow self.buttonOpen.clicked.connect(self.file_dialog) def file_dialog(self): fd = QtGui.QFileDialog(self) self.filename = fd.getOpenFileName() from os.path import isfile if isfile(self.filename): text = open(self.filename).read() self.editorWindow.setText(text) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = StartQT4() myapp.show() sys.exit(app.exec_())
The main problem with your code is that you are using the wrong base-class for your
StartQT4
subclass. It should match the top-level class from Qt Designer, which is aQDialog
.You can also simplify your code a little, by adding the ui directly to your sub-class, and by using new-style signal and slot syntax.
With these changes in place, your code would look like this:
import sys from PyQt4 import QtCore, QtGui from simpleTextEditor_gui import Ui_simpleTextEditor class StartQT4(QtGui.QDialog, Ui_simpleTextEditor): def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setupUi(self) # tutaj dajemy wlasne polaczenia slotow self.buttonOpen.clicked.connect(self.file_dialog) def file_dialog(self): fd = QtGui.QFileDialog(self) self.filename = fd.getOpenFileName() from os.path import isfile if isfile(self.filename): text = open(self.filename).read() self.editorWindow.setText(text) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = StartQT4() myapp.show() sys.exit(app.exec_())
相关问答
更多-
正如@Mike所说,你应该构造对话框对象,父对象传递给构造函数,而不是使用QObject::setParent() ,因为许多小部件属性依赖于父级及其属性,并且在调用setParent()时不会更改setParent() 。 如果这也解决了你的标题栏问题,请尝试。 As @Mike said, you are supposed to construct the dialog object with the parent passed to the constructor instead of using Q ...
-
使用qt designer指定的QDialog的valgrind问题(valgrind issue with QDialog specified with qt designer)[2023-08-17]
通过以下操作你会遇到麻烦: SuspendDialog suspend_dialog(this); // wrong! do not pass 'this' here 在Qt中将指针传递给'this'意味着您传递负责释放该小部件的父级。 或者,释放将发生两次:首先当堆栈上的对象被破坏时,然后当父对象被破坏时。 如果使用exec()执行对话框,仍然可以在堆栈上分配对话框小部件,但不要将其传递给它: SuspendDialog suspend_dialog; // suspend_dialog.e ... -
Qt QDialog渲染堆叠(Qt QDialog rendering stacked)[2021-04-13]
您的代码的主要问题是您为StartQT4子类使用了错误的基类。 它应该与Qt Designer中的顶级类匹配,后者是QDialog 。 您还可以通过将ui直接添加到子类,以及使用新式信号和插槽语法来简化代码。 有了这些更改,您的代码将如下所示: import sys from PyQt4 import QtCore, QtGui from simpleTextEditor_gui import Ui_simpleTextEditor class StartQT4(QtGui.QDialog, Ui_sim ... -
子类QDialog并使用QDialogButtonBox作为标准按钮( docs )。 Subclass QDialog and use a QDialogButtonBox for the standard buttons (docs).
-
我认为使用Qt Designer是不可能的。 但是,您始终可以单独创建QDialog并稍后加载.ui文件。 您可以使用uic.loadUi方法。 这将使对话框的所有对象动态可用,并为您节省大量的开发时间。 这是一个非常简短的例子: import sys from PyQt5 import uic from PyQt5.QtWidgets import QApplication class WindowLoader: """ All windows and dialogs load he ...
-
qt应用程序的标准生成主文件包含以下行: int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } 主窗口在那里创建。 因此,在您的情况下,您可以在返回之前创建主窗口。 通过在构造函数中添加QString作为参数,url将在主窗口中可用。 所以mainWindow.cpp构造函数更改为: MainWindow::Main ...
-
它不是Qt记录的按钮。 您可以通过捕获事件并检查事件类型来检测此事件: http://qt-project.org/doc/qt-5/qevent.html#Type-enum 有不同的类型,如QEvent::EnterWhatsThisMode QEvent::WhatsThisClicked等。 我在mainwindow中使用事件过滤器实现了类似于你想要的东西。 if(event->type() == QEvent::EnterWhatsThisMode) qDebug() << "click" ...
-
QDialog缺少边框(QDialog missing border)[2022-05-16]
您可以通过调用布局上的setContentMargins来设置边框宽度。 例如: ui->myQDialog->setContentsMargins(3,3,3,3); // sets the qdialog border width to 3px. I Found the solution. It was outside the code. One of my colleagues change the Ubuntu config to force my application as full scre ... -
我认为你应该使用getSaveFileName I think you should use getSaveFileName instead
-
使用信号和插槽在Qt中与MainWindow通信QDialog(Using Signals and Slots to Comunicate a QDialog with MainWindow in Qt)[2022-09-15]
将函数MainWindow::on_pushButton_OpenWindow_clicked()更改为此 void MainWindow::on_pushButton_OpenWindow_clicked() { externalDialog->setModal(true); externalDialog->exec(); } 您刚刚在原始函数中创建了一个新的未连接对话框。 change function MainWindow::on_pushButton_OpenWindow_clic ...