Format content of messageBox
-
Hi ,
I'd like to show some message.
I will set the message to QString class and then show messageboxUnlucky, it is not what I want in the messagebox.
This is my example code
char *info[] = {"Apple", "Banana", "Strawberrie", "Grape"}; char tmp[1024]; QString s; for(int i=0; i<30; i=i+10) { for(int j=0; j<4; j++) { sprintf(tmp, "[%2d] %15s = %2d\n", i, info[j], j); s.append(tmp); } } qDebug() << s; QMessageBox::information(NULL, "Fruits", s, QMessageBox::Yes, QMessageBox::Yes);
The result
I want the content of messagebox same as the debug message.
How to do?Thanks a lot
-
@ChiaoHuang
Use a fixed width /mono spaced font. -
@mpergand
I am sorry for the late reply
I am trying it, but it doesn't work.msgFont.setStyleHint(QFont::Monospace); msg.setFont(msgFont); msg.setFixedWidth(1200); msg.setText(s); msg.setStandardButtons(QMessageBox::Yes); msg.exec();
Thanks
-
@ChiaoHuang
What type/declaration is thismsg
variable? It does not seem to obeymsg.setFixedWidth(1200);
either? Originally you usedQMessageBox::information()
which isstatic
, so what is going on now in your code?I only know that https://stackoverflow.com/a/22587461/489865 from 2014 claims to work, you could test that (with a suitable combobox populated, or hard-coded value). If it really does not work you could test out HTML
font
markup, or even QSS/CSS. -
@ChiaoHuang
try:msg.setFont(QFont("courier")); // or monaco or any fixed font name available on your system
or get the default fixed font with:
QFont font=QFontDatabase::systemFont(QFontDatabase::FixedFont);
-
@ChiaoHuang
I created a "QMessageBox msg" for using Font.
Yes, I don't know why the msg.setFixedWidth(1200) is not working.Thank you. I think the HTML font markup should work.
-
@mpergand said in Format content of messageBox:
msg.setFont(QFont("courier"));
Thank you so much
It is working now after I used msg.setFont(QFont("consolas"));