PDA

View Full Version : Why modeless dialog block keyboard input



franco.amato
14th April 2010, 07:17
Hi to all,
I wrote a very simple informative dialog:

.h

#ifndef __INFODLG_H__
#define __INFODLG_H__

#include "GeneratedFiles/ui_infoDlg.h"

#include <QDialog>

class MainWindow;
class QTimer;

class InfoDlg : public QDialog
{
Q_OBJECT

public:
InfoDlg( QWidget *parent );
virtual ~InfoDlg();

public slots:
void SetText(const QString&);
void CloseDialogAfter(int msec);

protected:

private:
Ui::infoDlg ui;
};

#endif __INFODLG_H__

and the .cpp


#include "InfoDlg.h"
#include <QTimer>

InfoDlg::InfoDlg( QWidget *parent )
: QDialog(parent)
{
ui.setupUi(this);
setWindowFlags( Qt::FramelessWindowHint | Qt::Dialog );
setAttribute( Qt::WA_DeleteOnClose );
setWindowOpacity(0.8);
}

InfoDlg::~InfoDlg()
{
}

void InfoDlg::SetText(const QString& text)
{
ui.infoLabel->setText(text);
}

// close the dialog after x msec
void InfoDlg::CloseDialogAfter(int msec)
{
QTimer::singleShot( msec, this, SLOT(close() ) );
}

Here the ui file for those that would reproduce the dialog


<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>infoDlg</class>
<widget class="QDialog" name="infoDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>382</width>
<height>92</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="infoLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

Here an example of usage of the dialog


void WaveWidget::EncodingStart()
{
dlg = new InfoDlg(this);
dlg->SetText("Encoding process started");
dlg->show();
}

void WaveWidget::EncodingEnd()
{
if( !m_WaveDisplay->m_ListaMarcatori.isEmpty() )
{
m_WaveDisplay->deteleMarkers();
}

m_WaveDisplay->waveSelectionStarted = false;

dlg->SetText("Encoding process finished");
dlg->CloseDialogAfter( 2000 );
}

The EncodingStart() and EncodingEnd() are two slot of WaveWidget connected to a separated thread so:


void WaveWidget::CutSound()
{
bool bg = false;
if( m_bgSndCheckBox->isChecked() )
bg = true;

WaveEncoder* encoderThread = new WaveEncoder( m_SoundName, m_outputDir, m_bgFile, bg, m_wave, m_WaveDisplay );
connect( encoderThread, SIGNAL( started() ), this, SLOT( CodificaStart() ) );
connect( encoderThread, SIGNAL( finished() ), this, SLOT( CodificaEnd() ) );

encoderThread->setOffset(m_soundOffset);
encoderThread->start();
}

I run the infoDlg in modeless mode with show() but unfortunately it block my gui ( gui doesn't accept further keyboard input and it's blocked ) I don't understand why.

franco.amato
15th April 2010, 02:08
anyone can reply please?