I am using the same setup (BeagleBone Black with eglfs2, QT5.5) and found another solution that might work depending on how you want the title presented. In my case, the QT project is a customized touchscreen-only app that does need the classic window looking frame. I found out if I use QMessageBox::setText() it puts the text to the right of the icon. If I use QMessageBox::setInformativeText() it places the text in the center of the window as expected. QMessageBox::setWindowTitle() never shows up.
So I wrote a derived class and overrode setWindowTitle() to call setText(). Made sure it was setup for Qt::AutoText so I could center and bold the title.
I also overrode the static information, critical, question and alert methods so I wouldn't have to modify (too much) existing code written for qt 4.X.
Source:
MessageBox::MessageBox(QWidget *parent) :
QMessageBox(parent)
{
setTextFormat(Qt::AutoText);
}
MessageBox::~MessageBox()
{
}
void MessageBox::setWindowTitle(QString titleStr)
{
setText("<center><b>" + titleStr + "</b></center>");
}
MessageBox::StandardButton MessageBox::messageBox(QWidget *parent, const QString &title,
const QString &text, MessageBox::StandardButtons buttons, MessageBox::StandardButton defaultButton,
QMessageBox::Icon icon)
{
MessageBox msgBox(parent);
msgBox.setWindowTitle(title);
msgBox.setInformativeText(text);
msgBox.setIcon(icon);
msgBox.setStandardButtons(buttons);
msgBox.setDefaultButton(defaultButton);
if (msgBox.exec() == -1)
return QMessageBox::Cancel;
return msgBox.standardButton(msgBox.clickedButton());
}
MessageBox::StandardButton MessageBox::information(QWidget *parent, const QString &title,
const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
{
return messageBox(parent, title, text, buttons, defaultButton, QMessageBox::Information);
}
MessageBox::StandardButton MessageBox::question(QWidget *parent, const QString &title,
const QString &text,MessageBox::StandardButtons buttons,MessageBox::StandardButton defaultButton)
{
return messageBox(parent, title, text, buttons, defaultButton, QMessageBox::Question);
}
MessageBox::StandardButton MessageBox::warning(QWidget *parent, const QString &title,
const QString &text,MessageBox::StandardButtons buttons,MessageBox::StandardButton defaultButton)
{
return messageBox(parent, title, text, buttons, defaultButton, QMessageBox::Warning);
}
MessageBox::StandardButton MessageBox::critical(QWidget *parent, const QString &title,
const QString &text,MessageBox::StandardButtons buttons,MessageBox::StandardButton defaultButton)
{
return messageBox(parent, title, text, buttons, defaultButton, QMessageBox::Critical);
}
Header:
class MessageBox : public QMessageBox
{
public:
MessageBox(QWidget *parent = NULL);
~MessageBox();
void setWindowTitle(QString titleStr);
static MessageBox::StandardButton information(QWidget *parent, const QString &title,
const QString &text, MessageBox::StandardButtons buttons = Ok,
MessageBox::StandardButton defaultButton = NoButton);
static MessageBox::StandardButton question(QWidget *parent, const QString &title,
const QString &text, MessageBox::StandardButtons buttons = MessageBox::StandardButtons(Yes | No),
MessageBox::StandardButton defaultButton = NoButton);
static MessageBox::StandardButton warning(QWidget *parent, const QString &title,
const QString &text, MessageBox::StandardButtons buttons = Ok,
MessageBox::StandardButton defaultButton = NoButton);
static MessageBox::StandardButton critical(QWidget *parent, const QString &title,
const QString &text, MessageBox::StandardButtons buttons = Ok,
MessageBox::StandardButton defaultButton = NoButton);
private:
static MessageBox::StandardButton messageBox(QWidget *parent, const QString &title,
const QString &text, MessageBox::StandardButtons buttons, MessageBox::StandardButton defaultButton,
QMessageBox::Icon icon);
};