Lv.的博客

QMessageBox改变大小

创建一个QMessageBox:

QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("MailBox Location"));
msgBox.setInformativeText(tr("You must ..... and so on and so forth"));

像这样改变它的大小:

1). msgbox.setGeometry ( int x, int y, int w, int h )
2). msgbox.resize(int w, int h)

结果什么都没有发生。

 

原因:QMessageBox::showEvent() 强制将其大小改变成了QT认为比较合适的大小。要改变它的大小可使用下面这种方法

 

class MyMessageBox : public QMessageBox

{
   protected:
      void showEvent(QShowEvent* event)

  {
     QMessageBox::showEvent(event);
     setFixedSize(640, 480);
   }
};

posted @ 2014-05-28 16:44  Avatarx  阅读(6304)  评论(0编辑  收藏  举报