PDA

View Full Version : costumize progress dialog



bossy
10th May 2012, 21:24
i want to create a simple animation when my tableview is updating. I managed to create a scene in a separate dialog, the problem is it doesnt get painted until the tableview gets repainted(when the updating is done), i try to use the QProgress Dialog class but didnt have much success, how do i get this dialog to repaint on a separate thread ?

thanks

ChrisW67
11th May 2012, 01:21
how do i get this dialog to repaint on a separate thread ?
You don't, at least not with Qt which requires painting to be done from the main thread.

Since you have not bothered to show any of your code we can only guess that you are blocking the program from reaching the Qt event loop.

bossy
11th May 2012, 21:52
code is a little messy so i'll try to make it as clear as possible


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
model = new QStandardItemModel(3000,15,this);
//then add all the items from a file to the model
tableView = new FreezeTableWidget(model);


ui->centralWidget->setLayout(boxLayout);
ui->centralWidget->layout()->addWidget(tableView);

connect(model,SIGNAL(dataChanged(QModelIndex,QMode lIndex)),this,SLOT(updateSearch()));

void MainWindow::updateSearch()
{
myprogressDialog *progress = new myprogressDialog;
progress->setMinimum(0);
progress->setMaximum(100);
//progress->setValue(50);
progress->show();

//hide all the row that do not contain the search word
for (int i=1;i<3000;i++)
if(tableView->isRowHidden(i))tableView->showRow(i);


QList<int> searchInUse;
for (int i=0;i<14;i++)
{
if (!model->index(0,i).data().toString().isEmpty())
{

searchInUse.append(i);
}
}
progress->hide();

//myprogressDialog.cpp which is mainly a rotation form

scene = new QGraphicsScene(this);
graph = new QGraphicsView(this);
graph->setFrameStyle(0);
graph->setScene(scene);
scene->setSceneRect(-100,-100,200,200);

waitD = new waitDisplay();

timer = new QTimer(this);
scene->addItem(waitD);
connect(timer, SIGNAL(timeout()), scene,SLOT(update()));
timer->start(20);

then again the myprogressDialog does not get painted until the tableview is updated

ChrisW67
13th May 2012, 03:39
For the duration of the loop at line 25 the program is not processing Qt events. This means that timers (in particular) and many other things will not function. You should have a read of Keeping the GUI Responsive for some ways to approach this.

myta212
16th May 2012, 16:59
Hi,
I get some of tutorial and sample code how to create a progressbar with thread at here :
http://hopf.chem.brandeis.edu/yanglingfa/Qt/threading/index.html
maybe you can use this.
Regards,

Myta