Results 1 to 2 of 2

Thread: Why modeless dialog block keyboard input

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Why modeless dialog block keyboard input

    Hi to all,
    I wrote a very simple informative dialog:

    .h
    Qt Code:
    1. #ifndef __INFODLG_H__
    2. #define __INFODLG_H__
    3.  
    4. #include "GeneratedFiles/ui_infoDlg.h"
    5.  
    6. #include <QDialog>
    7.  
    8. class MainWindow;
    9. class QTimer;
    10.  
    11. class InfoDlg : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. InfoDlg( QWidget *parent );
    17. virtual ~InfoDlg();
    18.  
    19. public slots:
    20. void SetText(const QString&);
    21. void CloseDialogAfter(int msec);
    22.  
    23. protected:
    24.  
    25. private:
    26. Ui::infoDlg ui;
    27. };
    28.  
    29. #endif __INFODLG_H__
    To copy to clipboard, switch view to plain text mode 

    and the .cpp

    Qt Code:
    1. #include "InfoDlg.h"
    2. #include <QTimer>
    3.  
    4. InfoDlg::InfoDlg( QWidget *parent )
    5. : QDialog(parent)
    6. {
    7. ui.setupUi(this);
    8. setWindowFlags( Qt::FramelessWindowHint | Qt::Dialog );
    9. setAttribute( Qt::WA_DeleteOnClose );
    10. setWindowOpacity(0.8);
    11. }
    12.  
    13. InfoDlg::~InfoDlg()
    14. {
    15. }
    16.  
    17. void InfoDlg::SetText(const QString& text)
    18. {
    19. ui.infoLabel->setText(text);
    20. }
    21.  
    22. // close the dialog after x msec
    23. void InfoDlg::CloseDialogAfter(int msec)
    24. {
    25. QTimer::singleShot( msec, this, SLOT(close() ) );
    26. }
    To copy to clipboard, switch view to plain text mode 

    Here the ui file for those that would reproduce the dialog
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>infoDlg</class>
    4. <widget class="QDialog" name="infoDlg">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>382</width>
    10. <height>92</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>Dialog</string>
    15. </property>
    16. <layout class="QVBoxLayout" name="verticalLayout">
    17. <item>
    18. <widget class="QLabel" name="infoLabel">
    19. <property name="text">
    20. <string/>
    21. </property>
    22. <property name="alignment">
    23. <set>Qt::AlignCenter</set>
    24. </property>
    25. </widget>
    26. </item>
    27. </layout>
    28. </widget>
    29. <resources/>
    30. <connections/>
    31. </ui>
    To copy to clipboard, switch view to plain text mode 

    Here an example of usage of the dialog

    Qt Code:
    1. void WaveWidget::EncodingStart()
    2. {
    3. dlg = new InfoDlg(this);
    4. dlg->SetText("Encoding process started");
    5. dlg->show();
    6. }
    7.  
    8. void WaveWidget::EncodingEnd()
    9. {
    10. if( !m_WaveDisplay->m_ListaMarcatori.isEmpty() )
    11. {
    12. m_WaveDisplay->deteleMarkers();
    13. }
    14.  
    15. m_WaveDisplay->waveSelectionStarted = false;
    16.  
    17. dlg->SetText("Encoding process finished");
    18. dlg->CloseDialogAfter( 2000 );
    19. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. void WaveWidget::CutSound()
    2. {
    3. bool bg = false;
    4. if( m_bgSndCheckBox->isChecked() )
    5. bg = true;
    6.  
    7. WaveEncoder* encoderThread = new WaveEncoder( m_SoundName, m_outputDir, m_bgFile, bg, m_wave, m_WaveDisplay );
    8. connect( encoderThread, SIGNAL( started() ), this, SLOT( CodificaStart() ) );
    9. connect( encoderThread, SIGNAL( finished() ), this, SLOT( CodificaEnd() ) );
    10.  
    11. encoderThread->setOffset(m_soundOffset);
    12. encoderThread->start();
    13. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why modeless dialog block keyboard input

    anyone can reply please?

Similar Threads

  1. How to delete modeless dialog?
    By rajesh in forum Qt Programming
    Replies: 15
    Last Post: 16th June 2009, 12:19
  2. Replies: 0
    Last Post: 2nd June 2009, 15:57
  3. Modeless dialog disappearing
    By Raccoon29 in forum Qt Programming
    Replies: 4
    Last Post: 15th September 2007, 11:38
  4. Replies: 5
    Last Post: 23rd February 2007, 10:23
  5. modeless dialog
    By mhoover in forum Newbie
    Replies: 2
    Last Post: 23rd March 2006, 22:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.