Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want the copy paste ability that QErrorMessage would have, you could create your own custom QDialog. First I would make a dialog.ui with a QTextEdit (textEdit) and a QPushButton (okButton). Make sure you name the dialog object in the .ui something meaningful (MessageDialog in this case). The code could be something like this:</p> <p>In your messagedialog.h:</p> <pre><code>class MessageDialog : public QDialog, public Ui::MessageDialog { Q_OBJECT private: Ui::MessageDialog *ui; public: MessageDialog(QWidget * parent = 0, QString msg = "", uint w = 200, uint h = 100); private slots: void on_okButton_clicked(); }; </code></pre> <p>In your messagedialog.cpp:</p> <pre><code>MessageDialog::MessageDialog(QWidget *parent, QString msg, uint w, uint h) : QDialog(parent), ui(new Ui::MessageDialog) { ui-&gt;setupUi(this); this-&gt;setFixedSize(w, h); this-&gt;ui-&gt;textEdit-&gt;setFixedSize( (w - 20), (h - 50) ); this-&gt;ui-&gt;textEdit-&gt;setGeometry( (this-&gt;geometry().left() + 10), 10, (ui-&gt;okButton-&gt;size().width()), (ui-&gt;okButton-&gt;size().height())); // I personally like to get rid of the ? next to close in the upper right, minimize, and maximize this-&gt;setWindowFlags(windowFlags() &amp; ~Qt::WindowContextHelpButtonHint); this-&gt;setWindowFlags(windowFlags() &amp; ~Qt::WindowMinimizeButtonHint); this-&gt;setWindowTitle("Message"); this-&gt;ui-&gt;textEdit-&gt;setText(msg); this-&gt;ui-&gt;okButton-&gt;setGeometry( (this-&gt;geometry().center().x() - (this-&gt;ui-&gt;okButton-&gt;width() / 2) ), (this-&gt;geometry().bottom() - (this-&gt;ui-&gt;okButton-&gt;height())) - 5, (ui-&gt;okButton-&gt;size().width()), (ui-&gt;okButton-&gt;size().height())); this-&gt;setFocus(); } void MessageDialog::on_okButton_clicked() { this-&gt;close(); } </code></pre> <p>Then wherever you want to use it:</p> <pre><code>QDialog *messageDialog = new MessageDialog(this, msg); messageDialog-&gt;exec(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload