I was running into the same problem. The width of the QMessageBox appears to be based on the width of the main text. If the InformativeText is significantly longer (as I would expect it to be), it will be wrapped. After reading this thread and other solutions from other sources, I created the following MessageBox class that appear to work:
{
Q_OBJECT
public:
explicit MessageBox
(QWidget *parent
= 0);
void setMinimumWidth(int minw);
protected:
private:
int width;
};
{
width = 0;
}
void MessageBox::setMinimumWidth(int minw)
{
width = minw;
}
{
QWidget *textField
= findChild<QWidget
*>
("qt_msgbox_label");
int curWidth = textField->width();
textField->setMinimumWidth(width);
int newWidth = textField->width();
this->move(pos().x() - (newWidth - curWidth) / 2, pos().y());
}
class MessageBox : public QMessageBox
{
Q_OBJECT
public:
explicit MessageBox(QWidget *parent = 0);
void setMinimumWidth(int minw);
protected:
void showEvent(QShowEvent *event);
private:
int width;
};
MessageBox::MessageBox(QWidget *parent) : QMessageBox(parent)
{
width = 0;
}
void MessageBox::setMinimumWidth(int minw)
{
width = minw;
}
void MessageBox::showEvent(QShowEvent *event)
{
QMessageBox::showEvent(event);
QWidget *textField = findChild<QWidget *>("qt_msgbox_label");
int curWidth = textField->width();
textField->setMinimumWidth(width);
textField->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
int newWidth = textField->width();
this->move(pos().x() - (newWidth - curWidth) / 2, pos().y());
}
To copy to clipboard, switch view to plain text mode
Hope this helps
Bookmarks