[Qt-interest] [Q]: How to make QMessageBox resizebale?
Girish Ramakrishnan
girish at forwardbias.in
Mon Apr 6 18:25:06 CEST 2009
Vladimir Romanovskiy wrote:
> Hi,
>
> Working with Qt4.4 , I want to have a resizable QMessageBox. Nothing
> really helps, what to do ?
>
> Here is the code.
>
> QMessageBox msgBox;
> msgBox.setWindowTitle( "test");
> msgBox.setText( text);
> msgBox.setDetailedText( textDetailed);
> msgBox.setStandardButtons( QMessageBox::Save | QMessageBox::Discard);
> msgBox.setDefaultButton( QMessageBox::Discard);
> msgBox.setIcon( QMessageBox::Question);
> msgBox.setTextFormat(Qt::AutoText);
> msgBox.setSizePolicy( QSizePolicy(QSizePolicy::Preferred,
> QSizePolicy::Preferred));
> msgBox.setSizeGripEnabled( true);
> msgBox.setWindowFlags( msgBox.windowFlags() ^
> Qt::MSWindowsFixedSizeDialogHint);
>
> if ( QTextEdit * pTextEdit = msgBox.findChild<QTextEdit *>() )
> pTextEdit->setHtml( textDetailed);
>
Your approach is correct. However, QMessageBox does not use the layout
to set a fixed size - it uses QWidget::setFixedSize. What's tricky is
that it would actually do this just about when its shown.
So add the following lines at this point in the code,
msgBox.show();
msgBox.setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); // override
setFixedSize of QMessageBox.
> if ( msgBox.exec() == QMessageBox::Save )
> {
> /*doSave()*/;
> }
>
Girish
More information about the Qt-interest-old
mailing list