I am working with QT creator and he has emerged a problem I could not solve ... I'm on a gui application, where I have a window with a button that calls "Scan" which when pressed runs a QProgressDialog while running a code that has a cycle heavy while .. up there all right, the problem arises when I press the cancel button of QprogressDialog, normally closed and asks if dialog.wascancelled cycle () break. everything perfect until the dialog closes the cycle is interrupted and return to my initial window .. But here is where the problem is if I press the button "Scan" opens again but his condition qprogressdialog wascancelled () remains true, which upon entering the cycle and ask if wascancelled () automatically goes without nothing ... As I can do to change the status of wascancelled () to false?, There are some property for this or I can do to achieve my goal to avoid breaking the cycle after entering a first time?
You should call QProgressDialog::reset().
Related
I have a button which when clicked will run back-end process for, say, 10 sec.
I would like to make the button in pressed state till the process completes and then the button be released. This is, so that the user knows when the process is complete. As an example:
QString ExButtonStyleSheet = "QPushButton{background-color:lightgreen;}\
QPushButton:hover{background-color:yellow;}\
QPushButton:pressed{background-color:green;}\
QPushButton:disabled{background-color:grey;}";
In the above case, once clicked the button goes to hover state (yellow) even when the process is running (GUI is also busy) and turns lightgreen once free.
But this is not very explicit to the user, unlike the pressed state.(Note the above stylesheet is just an example and in my actual styesheet the hover state color is only slightly different from the normal.)
I am looking for a solution where the button remains to look pressed and only to be released when the process is complete.
You can theoretically use
QPushButton::setCheckable(true)
QPushButton::setDown(true) // Button is down
// Expensive task
QPushButton::setDown(false) // Button is released
Freezing the GUI for 10 seconds is a very bad idea.
You should use threads for your expensive tasks instead of blocking the GUI. Call QPushButton::setDown(true) and emit a signal to the thread which contains the code of the expensive task.
When the thread finishes the thread should call a slot in your MainWindow that contains QPushButton::setDown(false). This way your GUI will be fully responsive during the time and you follow the good coding behaviours.
I am using 'Click Button' from ExtendedSelenium2Library to select Login button on my login page.
But is takes more than 12 seconds to select the Button. With Selenium2library it works immediately.
I prefer using Extendedselenium2 instead of selenium2. How to make it click faster?
TL;DR
Click Button ${button} True
Seems you already figured this out, but I had the same problem and it took some time to figure it out. So this is for future reference.
ExtendedSelenium2Library waits for AngularJs to be ready to process the next request. As can be seen here ExtendedSelenium2Library (and like you already said). So by using these commands that wait for Angular to be ready, when you are not using AngularJS, it is necessary for the timeout to kick in which is about the 12-14 seconds you experienced. To still be able to use the extended library and have "fast clicking" you need to set the argument "skip ready" to "True".
Example:
Click Element xpath=//a[#href="#/motor"]
Becomes
Click Element xpath=//a[#href="#/motor"] True
I have a button widget I'd like to fade out (self.button1)
def button_slot(self):
fade_effect = QtGui.QGraphicsOpacityEffect()
self.button1.setGraphicsEffect(fade_effect)
hideAnimation = QtCore.QPropertyAnimation(fade_effect, "opacity")
hideAnimation.setDuration(5000)
hideAnimation.setStartValue(1.0)
hideAnimation.setEndValue(0.0)
hideAnimation.start(QtCore.QPropertyAnimation.DeleteWhenStopped)
self.hideAnimation = hideAnimation
The code is in PyQt, but is the same as the original Qt.
For a reason, the when I try the code separately in a test file, it works well.
However, when trying to integrate it in my code, it seems like the fading out animation is running in the background, but not updated in the GUI itself:
The button is stuck at the "clicked" state.
If I minimize and enlarge the window, The button's opacity is right where it's supposed to be (for example, if the duration is 5000ms from 1.0 to 0.0, enlarging the window after 2500ms will show 0.5 opacity).
The button is clickable even though it looks "stuck".
Why could this be happening? How can I force the GUI to update itself at every event iteration?
The only possible explanation I have is that you're blocking the event loop somewhere else in your code. The animation will definitely run, as your test case shows, but it's invoked from the event loop. If your code blocks -- if there's any place in your code where you wait for things, sleep, etc., then that's your problem.
GUI code in Qt and many other frameworks must be written in run-to-completion fashion. Every slot and event handler must execute as quickly as it can, and then return. When you add a breakpoint in a slot, and look at the stack trace when the code stops, you'll see that QEventLoop::exec() is somewhere there. Ultimately, all GUI code is called from the event loop.
Try reducing your code piecewise until the problem vanishes. That's how you'll know where the blocking part is. Qt provides, unfortunately, many methods named waitxxx(), and they tend to be used without understanding that they block the event loop. A blocked event loop means that the application does not respond to user interaction, and eventually the OS will detect it and issue a spinning beachball (OS X), a spinning circle (Vista/Win7) or perhaps a message about a stuck application. A spinning beachball/circle means that the application's main event loop is blocked.
Im using Qt framework , and i looking for the best method to show the user im processing something
how in Qt i can:
put the main window in the background and pop up window to the foreground with
for example " processing " massage
until its done processing the " processing " window will close and the main window returns to the foreground .
Use QProgressDialog. It is designed for that kind of use. You can use the QProgressDialog as a modal dialog thus preventing any user interaction to your main window. QProgressDialog also gives you an easy way to present the progress of your processing and an optional pushbutton to abort processing.
Edit:
QProgressBar can be used in two states: progressing in steps or just showing busy state.
QProgressDialog's progress bar cannot be used showing busy state because that would require setting QProgressDialog's min and max values to 0, which immediately closes the progress dialog. However, you can give the QProgressDialog a new progress bar using setBar()-function. Then you can set this progress bar's min, max and value to 0 and then getting the busy look.
QProgressDialog progressDialog("Processing...", "Abort", 0, INT_MAX, this);
QProgressBar* bar = new QProgressBar(&progressDialog);
bar->setRange(0, 0);
bar->setValue(0);
progress.setBar(bar);
progressDialog.setMinimumWidth(350);
progressDialog.setMinimumDuration(1000);
progressDialog.setWindowModality(Qt::WindowModal);
progressDialog.setValue(0);
// Do your time consuming processing here, but remember to change
// the progress dialog's value a few times per second.
// That will keep the busy indicator moving.
progressDialog.setValue(progressDialog.value() + 1);
// And check if the user has cancelled the processing
if (progressDialog.wasCanceled())
break or return or whatever necessary
// When your processing is done, close the dialog.
progressDialog.close();
You can try that:
In the function that call the pop-up just hide the main window once the process pop-up displayed.
Connect the end processing signal to the main window slot Show(). If you have not predefined signal for that, create one and emit it.
emit NameOfSignal;
Hope that helps
Edit:
For disabling the main window use setDisabled instead of hide and setEnabled instead of show.
You can give your "Processing"-window the Qt::WindowStaysOnTopHint to make it stay on top of your disabled main window.
If it's not to fancy for you, you can blur your main window using QGraphicsBlurEffect while the processing window is on top. That way the user gets the impression of the main window to be not accessable until your processing is done.
I have made a simple qt program that grabs a picture and display it using QPainter/QPaintEvent widget. I make it on QPainter so that I can put a X mark on the picture from a user input. I have made the program window to hide and show based on an external button input. It works well if I set the running program window inactive. But if I set the window to active and triggered the show/hide function, it crashes with error:
Fatal IO error: client killed
Also, when I tried to use show() function after hide(), it gives 2-3 of a same error (applies when the window either active and inactive):
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread
Is this a bug in qt? Any suggestion on workaround this problem?