Results 1 to 10 of 10

Thread: Making form translucent and an animated pop up while running QProcess

  1. #1
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Making form translucent and an animated pop up while running QProcess

    Hi,

    I am running a QProcess that scans for available bluetooth devices. When this process is going on, I would like to make the QWidget form translucent and a pop up window with an animation like a sand watch moving in circles with a text saying scanning.. At the end of the process the pop up form should disappear and the QWidget should be in focus again. Is it possible to do it in QT? If so could you please direct me how to go about it. Maybe some examples?

    Thank you so much in advance for your help

    Giselle

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Making form translucent and an animated pop up while running QProcess

    For the popup you could use a QDialog subclass with a QLabel and a QMovie for the animation.

    You could connect the finished signal of your scanning to the dialog's close() slot and then call its exec() method.

    Most system will apply some effect on the underlying window themselves, so I am not sure whether making it semi-transparent as well is a good idea.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    gfernandes (29th October 2013)

  4. #3
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Re: Making form translucent and an animated pop up while running QProcess

    Hi,

    Thank you for your reply. I created a QDialog the way you told me to. It is working fine. The only problem is I do not know how to show it when the QProcess is running the scan. Following are the ways I followed and failed

    1. I connected the QPushButton clicked() function that calls a function to start the QProcess with a function which calls the show() function for QDialog

    This shows the QDialog after the scanning process is finished

    2. In the function where the QProcess does the scanning of Bluetooth devices, at the start of the function I call another function to show() QDialog, at the end of the scanning function I call another function to close() QDialog.

    This works the way I want. It opens the QDialog when I press the scan button and disappears when the function finishes,but it shows the QDialog as just a frame with nothing inside.

    I do not know how to go about it

    Please do help

    Giselle

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Making form translucent and an animated pop up while running QProcess

    That sounds like the event loop being blocked by something, e.g. the slot that starts the QProcess not returning.

    Can you post that code?

    Btw, one option to show the dialog when the process starts and hide it when it finishes is to connect the dialogs show/hide to the started/finished signals of the process.

    Cheers,
    _

  6. #5
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Re: Making form translucent and an animated pop up while running QProcess

    btconnect.h
    Qt Code:
    1. #ifndef BTCONNECT_H
    2. #define BTCONNECT_H
    3.  
    4. #include "scandialog.h"
    5.  
    6. namespace Ui {
    7. class BTConnect;
    8. }
    9.  
    10. class BTConnect : public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit BTConnect(QWidget *parent = 0);
    16. ~BTConnect();
    17.  
    18. private slots:
    19. void on_ScanButton_clicked();
    20.  
    21. void ScanBTDevices();
    22.  
    23. //some slots here
    24.  
    25. void ScanDialogShow();
    26.  
    27. void ScanDialogClose();
    28.  
    29. public slots:
    30. //some slots here
    31.  
    32. private:
    33. Ui::BTConnect *ui;
    34.  
    35. QProcess BTscan_Process;
    36.  
    37. scanDialog *scan;
    38. };
    39.  
    40. #endif // BTCONNECT_H
    To copy to clipboard, switch view to plain text mode 


    btconnect.cpp

    Qt Code:
    1. BTConnect::BTConnect(QWidget *parent) :
    2. QWidget(parent),
    3. ui(new Ui::BTConnect)
    4. {
    5. //set the userinterface as BTConnect.ui
    6. ui->setupUi(this);
    7.  
    8. scan = new scanDialog(this);
    9. }
    10.  
    11.  
    12. void BTConnect::ScanDialogShow()
    13. {
    14. scan->show();
    15. }
    16.  
    17. void BTConnect::ScanDialogClose()
    18. {
    19. scan->close();
    20. }
    21.  
    22. void BTConnect::ScanBTDevices()
    23. {
    24. ScanDialogShow();
    25.  
    26. //Command to scan nearby bluetooth devices
    27. //"hcitool scan"
    28. QString cmd("hcitool scan");
    29.  
    30. //start the process
    31. BTscan_Process.start(cmd);
    32.  
    33. //Wait for the processs to finish with a timeout of 20 seconds
    34. if(BTscan_Process.waitForFinished(20000))
    35. {
    36. //Clear the list widget
    37. this->ui->listWidget->clear();
    38.  
    39. //Read the command line output and store it in QString out
    40. QString out(BTscan_Process.readAllStandardOutput());
    41.  
    42. //Split the QString every new line and save theve in a QStringList
    43. QStringList OutSplit = out.split("\n");
    44.  
    45. //Parse the QStringList in btCellsParser
    46. btCellsParser cp(OutSplit);
    47.  
    48. for(unsigned int i = 0; i<cp.count(); i++)
    49. {
    50. //writing in listwidget
    51. }
    52.  
    53. }
    54.  
    55. ScanDialogClose();
    56. }
    57.  
    58. void BTConnect::on_ScanButton_clicked()
    59. {
    60. //Scan for available nearby bluetooth devices
    61. ScanBTDevices();
    62. }
    To copy to clipboard, switch view to plain text mode 


    This is my code for the second method I told earlier

  7. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Making form translucent and an animated pop up while running QProcess

    An easy way would be to show a gif file as animation rather than doing it yourself.

    Also is your scan dialog modal or non modal ??

  8. #7
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Re: Making form translucent and an animated pop up while running QProcess

    scandialog.h

    Qt Code:
    1. #ifndef SCANDIALOG_H
    2. #define SCANDIALOG_H
    3.  
    4. #include <QDialog>
    5.  
    6. namespace Ui {
    7. class scanDialog;
    8. }
    9.  
    10. class scanDialog : public QDialog
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit scanDialog(QWidget *parent = 0);
    16. ~scanDialog();
    17.  
    18. private:
    19. Ui::scanDialog *ui;
    20. };
    21.  
    22. #endif // SCANDIALOG_H
    To copy to clipboard, switch view to plain text mode 

    scandialog.cpp
    Qt Code:
    1. #include "scandialog.h"
    2. #include "ui_scandialog.h"
    3. #include <QMovie>
    4.  
    5. #define PATH_TO_GIF "/root/QTProjects/GIF files/sandwatch.GIF"
    6.  
    7. scanDialog::scanDialog(QWidget *parent) :
    8. QDialog(parent),
    9. ui(new Ui::scanDialog)
    10. {
    11. ui->setupUi(this);
    12. QMovie *movie = new QMovie(PATH_TO_GIF);
    13. this->ui->movieLabel->setMovie(movie);
    14. movie->start();
    15. }
    16.  
    17. scanDialog::~scanDialog()
    18. {
    19. delete ui;
    20. }
    To copy to clipboard, switch view to plain text mode 

    I set the modal property for scandialog as true in btconnect.cpp


    Added after 35 minutes:


    if I change show() to exec(), the scandialog is shown with the animated sandwatch.. but the QProcess does not start. How do I do both simultaneously?

    Kindly please help
    Last edited by gfernandes; 29th October 2013 at 14:47.

  9. #8
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Re: Making form translucent and an animated pop up while running QProcess

    I asked the same question in stackoverflow.com and got an amazing solution

    http://stackoverflow.com/questions/1...ect=1#19664531

    Qt Code:
    1. void BTConnect::on_BTscanFinished()//new slot
    2. {
    3. //Clear the list widget
    4. this->ui->listWidget->clear();
    5.  
    6. //Read the command line output and store it in QString out
    7. QString out(BTscan_Process.readAllStandardOutput());
    8.  
    9. //Split the QString every new line and save theve in a QStringList
    10. QStringList OutSplit = out.split("\n");
    11.  
    12. //Parse the QStringList in btCellsParser
    13. btCellsParser cp(OutSplit);
    14.  
    15. for(unsigned int i = 0; i<cp.count(); i++)
    16. {
    17. //writing in listwidget
    18. }
    19. ScanDialogClose();
    20. }
    21.  
    22. void BTConnect::ScanBTDevices()
    23. {
    24. ScanDialogShow();
    25.  
    26. //Command to scan nearby bluetooth devices
    27. //"hcitool scan"
    28. QString cmd("hcitool scan");
    29.  
    30. //start the process
    31. connect(BTscan_Process, SIGNAL(finished()), this, SLOT(on_BTscanFinished()));
    32. BTscan_Process.start(cmd);
    33. QTimer::singleShot(20000, scan, SLOT(close()));
    34. }
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Making form translucent and an animated pop up while running QProcess

    Yes, your problem was that you called waitForFinished(), which blocks the caller. Since the caller is the UI Thread, it can't process any UI events, like showing or updating the dialog.

    Regarding your solution: I would recommend to connect the timer to the process, i.e. make the timer stop the scanning, and close the dialog when the process has finished.

    Otherwise you close the dialog and needlessly keep scanning.

    And do the connect in the constructor, otherwise each call to the "start scan" slot connects again, resulting in multiple invocations of the "scan finished" slot

    Cheers,
    _

  11. The following user says thank you to anda_skoa for this useful post:

    gfernandes (4th November 2013)

  12. #10
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Re: Making form translucent and an animated pop up while running QProcess

    Thank you.. Did all the modifications you suggested. Thank you so much. You're awesome!

Similar Threads

  1. Running an script using QProcess
    By DiegoTc in forum Newbie
    Replies: 1
    Last Post: 31st December 2010, 19:02
  2. Replies: 12
    Last Post: 11th September 2010, 02:39
  3. Replies: 0
    Last Post: 26th August 2010, 11:44
  4. [QtEmbedded] Translucent QGraphicsView with animated child widgets
    By zuck in forum Qt for Embedded and Mobile
    Replies: 13
    Last Post: 8th January 2010, 13:09
  5. Making the whole window/form scrollable
    By ike in forum Qt Tools
    Replies: 2
    Last Post: 6th October 2008, 20:24

Tags for this Thread

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.