确定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_())

相关问答

更多

Qt - QDialog小时候没有标题栏(Qt - QDialog as a child does not have title bar)

正如@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 us...

使用qt designer指定的QDialog的valgrind问题(valgrind issue with QDialog specified with qt designer)

通过以下操作你会遇到麻烦: SuspendDialog suspend_dialog(this); // wrong! do not pass 'this' here 在Qt中将指针传递给'this'意味着您传递负责释放该小部件的父级。 或者,释放将发生两次:首先当堆栈上的对象被破坏时,然后当父对象被破坏时。 如果使用exec()执行对话框,仍然可以在堆栈上分配对话框小部件,但不要将其传递给它: SuspendDialog suspend_dialog; // suspend_dia...

Qt QDialog渲染堆叠(Qt QDialog rendering stacked)

您的代码的主要问题是您为StartQT4子类使用了错误的基类。 它应该与Qt Designer中的顶级类匹配,后者是QDialog 。 您还可以通过将ui直接添加到子类,以及使用新式信号和插槽语法来简化代码。 有了这些更改,您的代码将如下所示: import sys from PyQt4 import QtCore, QtGui from simpleTextEditor_gui import Ui_simpleTextEditor class StartQT4(QtGui.QDialog, U...

带有确定和取消按钮的QDialog(QDialog with ok and cancel buttons)

子类QDialog并使用QDialogButtonBox作为标准按钮( docs )。 Subclass QDialog and use a QDialogButtonBox for the standard buttons (docs).

在QT Designer中使用QDialog(Using QDialog in QT Designer)

我认为使用Qt Designer是不可能的。 但是,您始终可以单独创建QDialog并稍后加载.ui文件。 您可以使用uic.loadUi方法。 这将使对话框的所有对象动态可用,并为您节省大量的开发时间。 这是一个非常简短的例子: import sys from PyQt5 import uic from PyQt5.QtWidgets import QApplication class WindowLoader: """ All windows and dialogs lo...

如何使用Qt C ++在QDialog Window和QMainWindow之间进行通信(How to communicate between QDialog Window and QMainWindow with Qt C++)

qt应用程序的标准生成主文件包含以下行: int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } 主窗口在那里创建。 因此,在您的情况下,您可以在返回之前创建主窗口。 通过在构造函数中添加QString作为参数,url将在主窗口中可用。 所以mainWindow.cpp构造函数更改为: MainWindow:...

QDialog:如何使用问号(?)按钮?(QDialog: how to use question mark (?) button?)

它不是Qt记录的按钮。 您可以通过捕获事件并检查事件类型来检测此事件: http://qt-project.org/doc/qt-5/qevent.html#Type-enum 有不同的类型,如QEvent::EnterWhatsThisMode QEvent::WhatsThisClicked等。 我在mainwindow中使用事件过滤器实现了类似于你想要的东西。 if(event->type() == QEvent::EnterWhatsThisMode) qDebug() << "c...

QDialog缺少边框(QDialog missing border)

您可以通过调用布局上的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...

qt c ++ QDialog打开新文件(qt c++ QDialog open new file)

我认为你应该使用getSaveFileName I think you should use getSaveFileName instead

使用信号和插槽在Qt中与MainWindow通信QDialog(Using Signals and Slots to Comunicate a QDialog with MainWindow in Qt)

将函数MainWindow::on_pushButton_OpenWindow_clicked()更改为此 void MainWindow::on_pushButton_OpenWindow_clicked() { externalDialog->setModal(true); externalDialog->exec(); } 您刚刚在原始函数中创建了一个新的未连接对话框。 change function MainWindow::on_pushButton_OpenWindow...

相关文章

更多

Java 重写(Override)与重载(Overload)

Java 重写(Override)与重载(Overload) 重写(Override) ...

Guava学习笔记:复写的Object常用方法

  在Java中Object类是所有类的父类,其中有几个需要override的方法比如equals,h ...

这个测试,为什么总是false

//TPoint.java/* This is just a trivial &quot;struct ...

solr dataimport 数据导入源码分析(七)

在solr dataimport 数据导入源码分析(五)提到了contextimpl类调用DataIm ...

瞬间覆盖百万微信用户的新玩法 逼格高到没朋友

最近朋友圈我们先后玩了两次有趣的九宫格玩法。大家可以看到今天的文章配图,是不是很有创意,但点开之后发现 ...

2009无线通信五大趋势 3G范围将覆盖全球

来自服务高通的一家公关公司日前发出文章,对2009年全球无线通信市场作出预测。文章称,对于全球无线通信 ...

solr dataimport 数据导入源码分析(五)

我们注意到EntityProcessorWrapper的初始化方法 @Override pub ...

spring的jdbctemplet的queryforObject()有异常,不知道原因

public String execute()throws Exception{ if(&quot; ...

XStream的日期转换XStreamDateConverter

1.如果Date类型是元素,可参考http://huyumin.iteye.com/blog/2072 ...

教你用大功率路由器实现覆盖3平方公里wix公众账号吸粉神器

相信大家对WiFi广告路由器已经不再陌生了,但是广告距离太近了,用处不大。那么,有没有一种简单的办法将 ...

最新问答

更多

您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)

将diff文件复制到存储库的根目录,然后执行以下操作: git apply yourcoworkers.diff 有关apply命令的更多信息, apply 见其手册页 。 顺便说一下:一个更好的方法是通过文件交换整个提交文件是发送者上的命令git format-patch ,然后在接收器上加上git am ,因为它也传送作者信息和提交信息。 如果修补程序应用程序失败,并且生成diff的提交实际上在您的备份中,则可以使用尝试在更改中合并的apply程序的-3选项。 它还适用于Unix管道,如下

将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)

尝试将第二行更改为snprintf(buf1, sizeof buf1, "%.2f", balance1); 。 另外,为什么要声明用该特定表达式分配缓冲区的存储量? EDIT @LưuVĩnhPhúc在下面的评论中提到我的原始答案中的格式说明符将舍入而不是截断,因此根据如何在不使用C舍入的情况下截断小数,您可以执行以下操作: float balance = 200.56866; int tmp = balance1 * 100; float balance1 = tmp / 100.0; c

OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)

这是简单的解决方案 在你需要写的控制器中 BackendMenu::setContext('Archetypics.Team', 'website', 'team'); 请参阅https://octobercms.com/docs/backend/controllers-views-ajax#navigation-context BackendMenu::setContext('Author.Plugin name', 'Menu code', 'Sub menu code'); 你需要在r

页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)

每当发出请求时ASP都会创建一个新的Page对象,并且一旦它将响应发送回用户就不会保留对该Page对象的引用,因此只要你找不到某种方法来保持生命自己引用该Page对象后,一旦发送响应, Page和只能通过该页面访问的所有对象才有资格进行垃圾回收。 ASP creates a new Page object whenever a request is made, and it does not hold onto the reference to that Page object once it

codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)

要在生产服务器中调试这个,你可以临时放 error_reporting(E_ALL); 并查看有哪些其他错误阻止正确的重定向。 您还应该检查生产服务器发送的响应标头。 它是否具有“缓存”,是否需要重新验证标头等 to debug this in production server, you can temporary put error_reporting(E_ALL); and see what other errors are there that prevents the proper

在计算机拍照在哪里进入

打开娥的电脑.在下面找到视频设备点击进去就可以了...

使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)

你是对的。 第一次输入后,换行符将保留在输入缓冲区中。 第一次读取后尝试插入: cin.ignore(); // to ignore the newline character 或者更好的是: //discards all input in the standard input stream up to and including the first newline. cin.ignore(numeric_limits::max(), '\n'); 您必须为#inc

No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)

for (int k = 0; k > 10; k++) { System.out.println(k); } k不大于10,所以循环将永远不会执行。 我想要什么是k<10 ,不是吗? for (int k = 0; k < 10; k++) { System.out.println(k); } for (int k = 0; k > 10; k++) { System.out.println(k); } k is not greater than 10, so loop

单页应用程序:页面重新加载(Single Page Application: page reload)

优点是不注销会避免惹恼用户,以至于他们会想要杀死你:-)。 说真的,如果每次刷新页面时应用程序都会将我注销(或者在新选项卡中打开一个链接),我再也不会使用该应用程序了。 好吧,不要这样做。 确保身份验证令牌存储在刷新后的某个位置,即不在某些JS变量中,而是存储在cookie或本地存储中。 The advantage is that not logging off will avoid pissing off your users so much that they'll want to kill

在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)

EXECUTE IMMEDIATE 'SELECT '||field_val_temp ||' FROM tableb WHERE function_id = :func_val AND rec_key = :rec_key' INTO field_val USING 'STDCUSAC' , yu.rec_key; 和, EXECUTE IMMEDIATE 'UPDATE tablec SET field_val_'||i||' = :field_val' USI