首页 \ 问答 \ 确定Equals()是否为覆盖?(Determine if Equals() is an override?)

确定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
更新时间:2023-05-09 14:05

最满意答案

您的代码的主要问题是您为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 a QDialog.

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 ...
  • 通过以下操作你会遇到麻烦: SuspendDialog suspend_dialog(this); // wrong! do not pass 'this' here 在Qt中将指针传递给'this'意味着您传递负责释放该小部件的父级。 或者,释放将发生两次:首先当堆栈上的对象被破坏时,然后当父对象被破坏时。 如果使用exec()执行对话框,仍然可以在堆栈上分配对话框小部件,但不要将其传递给它: SuspendDialog suspend_dialog; // suspend_dialog.e ...
  • 您的代码的主要问题是您为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" ...
  • 您可以通过调用布局上的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
  • 将函数MainWindow::on_pushButton_OpenWindow_clicked()更改为此 void MainWindow::on_pushButton_OpenWindow_clicked() { externalDialog->setModal(true); externalDialog->exec(); } 您刚刚在原始函数中创建了一个新的未连接对话框。 change function MainWindow::on_pushButton_OpenWindow_clic ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。