qmessagebox

How can I get access to a QMessageBox by QTest

一曲冷凌霜 提交于 2019-12-10 10:37:24
问题 I am creating some automated GUI tests in my application using QTest . I can access the widgets from my application using the command: savePushButton = mainWindow->findChild<QPushButton *>("savePushButton"); It is working fine, but now I have to click on the OK button of a QMessageBox . I created the QMessageBox in my application like this: if( something_wrong ) { QMessageBox::warning(new Widget(), "Title", "Something wrong!"); } How can I have access to this QMessageBox , and its buttons?

Will QMessageBox block the running of the whole main thread in Qt?

混江龙づ霸主 提交于 2019-12-08 10:30:30
问题 I am new to Qt My situation is: For some reason, I have to emit a heartbeat signal from the main thread, at the same time I would like to create a QMessageBox window using: reply = QMessageBox::question(this, tr("Sure want to quit?"), tr("Sure quit?"), QMessageBox::Yes|QMessageBox::No); I just want this message box to block user's input from other windows, but I do not want to block the heartbeat signal. How should I do this? Or is this done by default in Qt? 回答1: QMessageBox::question

QMessageBox with a countdown timer

懵懂的女人 提交于 2019-12-07 13:28:58
问题 I wanted to know what would be the best approach of adding a countdown timer to a QMessageBox ? For instance when a message box is displayed the countdown timer starts for say 5 seconds. If the user doesn't respond to the Message box the message box picks up a default choice. 回答1: How about something like this: #include <QMessageBox> #include <QPushButton> #include <QTimer> class TimedMessageBox : public QMessageBox { Q_OBJECT public: TimedMessageBox(int timeoutSeconds, const QString & title,

PyQt5简单开发

回眸只為那壹抹淺笑 提交于 2019-12-06 17:01:34
1.窗口类型 QMainWindow:可以包含菜单栏、工具栏、标题栏、状态栏,是最常见的窗口形式 QWidgets:不确定窗口的用途,使用QWidgets QDialog:对话窗口的基类,用于执行短期任务,没有菜单栏、工具栏、状态栏 2.创建窗体应用程序 import sys from PyQt5.QtWidgets import QMainWindow, QApplication class MainWin(QMainWindow): def __init__(self): super(MainWin, self).__init__() self.setWindowTitle("抓取工具") self.resize(400, 300) self.status = self.statusBar() self.status.showMessage('抓取工具') if __name__ == "__main__": app = QApplication(sys.argv) mainWin = MainWin() mainWin.show() sys.exit(app.exec_()) 从Main中可知,创建窗体程序,先要创建QApplication对象即应用对象,然后创建窗口对象(继承自三种窗口类型),然后调用窗口的显示函数show(),注意:没有show函数,运行时指挥创建相关进程

How can I get access to a QMessageBox by QTest

醉酒当歌 提交于 2019-12-06 03:47:44
I am creating some automated GUI tests in my application using QTest . I can access the widgets from my application using the command: savePushButton = mainWindow->findChild<QPushButton *>("savePushButton"); It is working fine, but now I have to click on the OK button of a QMessageBox . I created the QMessageBox in my application like this: if( something_wrong ) { QMessageBox::warning(new Widget(), "Title", "Something wrong!"); } How can I have access to this QMessageBox , and its buttons? I found a solution on the following link: http://www.qtcentre.org/threads/31239-Testing-modal-dialogs

QT中QMessageBox添加倒计时

烈酒焚心 提交于 2019-12-06 02:35:13
QMessageBox添加倒计时,一定时间内选择确定或者取消,否则倒计时结束,默认选择确定 直接上代码 main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); w.resize(800,600); return a.exec(); } widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QTimer> #include <QPushButton> #include <QMessageBox> #include <QDebug> #include <iostream> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget* parent = 0); ~Widget(); private: QTimer* timer_countdown; QPushButton* btn; QMessageBox* msgbox; QPushButton* okbtn; QPushButton* cancelbtn;

How can I resize QMessageBox?

不羁的心 提交于 2019-12-05 13:39:12
问题 I have a QMessageBox which I'd like it to be bigger. It's a simple QMessageBox with two standard buttons, Ok and Cancel. The problem is that it is very small for my application's purposes. Code shows like this: QMessageBox msg; msg.setText("Whatever"); msg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); msg.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); int ret = msg.exec(); switch (ret) { case QMessageBox::Ok: ui->textEdit->clear(); break; case QMessageBox::Cancel:

Setting parent for a QMessageBox

大兔子大兔子 提交于 2019-12-05 12:29:23
i can't understand what's the benefit of setting parent for a QMessageBox , for instance in the following code: void mainWindow::showMessage(QString msg) { QMesageBox::information(this, "title", msg); //'this' is parent } can somebody help me ? Probably a few things. First of all QMessageBox inherits from QDialog . Since QDialog has a concept of a parent, QMessageBox should too for consistency. Specifically, the documentation says: parent is passed to the QDialog constructor. At the very least, a new dialog is often displayed centered in top of its parent. However, there is more! According to

closing pyqt messageBox with closeevent of the parent window

佐手、 提交于 2019-12-04 20:05:37
I have folllowing piece of cake def __init__(): self._taskInProgress = threading.Event() def isFinished(self): self._taskInProgress.clear() self.progressBar.hide() self.close() def closeEvent(self, event): if self._taskInProgress.is_set(): reply = QtGui.QMessageBox.question(self, "Are you sure you want to quit? ", "Task is in progress !", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: event.accept() else: event.ignore() the problem is if somebody closes the parent window(i.e. self) the above prompt shows up , but if somebody doesn't press yes or no in this

How can I resize QMessageBox?

拈花ヽ惹草 提交于 2019-12-04 00:01:25
I have a QMessageBox which I'd like it to be bigger. It's a simple QMessageBox with two standard buttons, Ok and Cancel. The problem is that it is very small for my application's purposes. Code shows like this: QMessageBox msg; msg.setText("Whatever"); msg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); msg.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); int ret = msg.exec(); switch (ret) { case QMessageBox::Ok: ui->textEdit->clear(); break; case QMessageBox::Cancel: break;} I tried several ways to increase the size: msg.setSizePolicy(QSizePolicy::Expanding,QSizePolicy