一、模式
m_dlg = dlg;
m_dlg->setWindowFlags( Qt::Popup );
m_dlg->setModal( false );
m_dlg->setSizeGripEnabled( true );
connect( m_dlg, SIGNAL( textChanged( const QString&, int ) ),
this, SLOT( slot_textChanged( const QString&, int ) ) );
二、弹出的方式
void howPopup()
{
if ( !m_dlg )
return;
QPoint pos = mapToGlobal( rect().bottomLeft() );
if ( pos.x() < 0 )
pos.setX( 0 );
if ( pos.y() < 0 )
pos.setY( 0 );
if (( pos.x() + m_dlg->sizeHint().width() ) > QApplication::desktop()->availableGeometry().width() )
pos.setX( QApplication::desktop()->availableGeometry().width() - m_dlg->sizeHint().width() );
if (( pos.y() + m_dlg->sizeHint().height() + this->height() ) >
QApplication::desktop()->availableGeometry().height() )
pos.setY( pos.y() - m_dlg->sizeHint().height() - this->height() );
m_dlg->move( pos );
m_dlg->show();
}
博客给出了Qt对话框的相关代码。包括设置对话框模式,如设置窗口标志、模态状态、大小调整手柄等,还连接了文本改变信号与槽函数。同时展示了对话框弹出方式的代码,对弹出位置进行了边界判断和调整。
2195

被折叠的 条评论
为什么被折叠?



