本文介绍了问题与QMessageBox提示,不能改变其位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这种
int MainWindow::messageBox( QString button, QMessageBox::ButtonRole buttons, QString info, QMessageBox::Icon icon )
{
QFont f;
f.setPointSize(6);
QMessageBox *message = new QMessageBox(this);
message->setWindowModality(Qt::WindowModal);
message->setFont(f);
message->setText(info);
message->addButton( button, buttons );
message->setWindowTitle("MainWindow");
message->setIcon(icon);
message->move( this->width() / 2, this->height() / 2 );
return message->exec();
}
但我不能让QMessageBox提示转到屏幕的中心,我也尝试使用setGeometry,但它不工作。在这个任何想法?
But I can't make the qmessagebox go to the center of the screen, I also tried using setGeometry, but it doesn't work. Any ideas on this?
推荐答案
我解决了移动前用show()。这是code:
I solved using show() before moving it. This is the code:
int MainWindow::messageBox( QString button, QMessageBox::ButtonRole buttons, QString info, QMessageBox::Icon icon )
{
QFont f;
QMessageBox *message = new QMessageBox(this);
QDesktopWidget *win = new QDesktopWidget();
f.setPointSize(6);
message->setWindowModality(Qt::WindowModal);
message->setFont(f);
message->setText(info);
message->addButton( button, buttons );
message->setWindowTitle("MainWindow");
message->setIcon(icon);
message->show();
message->move( win->width() / 2 - message->width() / 2, win->height() / 2 - message->height() / 2 );
return message->exec();
}
这篇关于问题与QMessageBox提示,不能改变其位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!