简体   繁体   English

Qt 创建者,错误信息

[英]Qt creator, error message

I am a little rusty with QT but I've had to use it for projects before.我对 QT 有点生疏,但我以前不得不将它用于项目。

I was wondering if I could make a pop-up window, a small window with it's height/width disabled so the user can't expand it.我想知道我是否可以制作一个弹出窗口 window,一个小的 window,它的高度/宽度被禁用,因此用户无法展开它。 It should also lock the screen until they press a button on this window.它还应该锁定屏幕,直到他们按下这个 window 上的按钮。

I could do all of this in a separate class, but I was wondering.我可以在单独的 class 中完成所有这些,但我想知道。 Are there any built-in QT classes that have a little popup like this that I could just modify?是否有任何内置的 QT 类有一个像这样的小弹出窗口,我可以修改? I mean making a class just for an error message seems to me a little wasteful.我的意思是只为错误消息制作 class 在我看来有点浪费。 I'm trying to keep the project small.我正在努力使项目保持小型化。

But if a class is required to be made in order to accomplish this, that is fine.但是,如果需要制作 class 来完成此操作,那很好。 The only problem is I have no clue how to lock the application windows so that you have to do something one window before you can go back to the main application.唯一的问题是我不知道如何锁定应用程序 windows 以便您必须先执行一些操作 window 才能 go 返回主应用程序。

I'm not asking for someone to type out all this code for me, just give me a link or something.我不是要别人为我输入所有这些代码,只是给我一个链接或其他东西。 I've looked for it but I couldn't find it.我找过,但没找到。 Cheers.干杯。

QMessageBox messageBox;
messageBox.critical(0,"Error","An error has occured !");
messageBox.setFixedSize(500,200);

The above code snippet will provide the required message box.上面的代码片段将提供所需的消息框。

For a simple error message, I would suggest you look into the QMessageBox (the documentation contains little example that should show you how to easily achieve what you need), which is modal too.对于简单的错误消息,我建议您查看QMessageBox (文档中包含的小示例应该向您展示如何轻松实现所需的内容),它也是模态的。 Using a QDialog for displaying a simple error message is possible too, but maybe too much for such a simple task.使用 QDialog 来显示简单的错误消息也是可能的,但对于这样一个简单的任务来说可能太多了。

I believe what you are looking for is something along the lines of QDialog .我相信您正在寻找的是QDialog的内容。 Dialogs can be modal or nonmodal.对话框可以是模态的或非模态的。 Modal dialogue "block" interaction with the calling window until the Dialog window has been handled.模态对话“阻止”与调用 window 的交互,直到对话 window 已被处理。

You can either subclass QDialog or check to see if one of the default dialog classes will be enough for what you need.您可以继承 QDialog 或检查默认对话框类之一是否足以满足您的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM