Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

How can i stop listview and listWidget from flickering?

$
0
0
Hello everyone. I am trying to get the list of processes in a <1 ms intervals and then show the latest list in a listwidget or a listview. In the listWidget i am having lots of flickering happening! i tried listview it is even worse! this is my sample code : #include "frmprocess.h" #include "ui_frmprocess.h" #include "qprocess.h" #include <windows.h> #include <tlhelp32.h> #include "qstring.h" #include "qtimer.h" #include "qlist.h" #include "qmessagebox.h"   frmProcess::frmProcess(QWidget *parent) :  QMainWindow(parent),  ui(new Ui::frmProcess) {     ui->setupUi(this);       //setting timer     timer = new QTimer(this);     connect(timer,SIGNAL(timeout()),this,SLOT(OnTimerTick()));       model = new QStringListModel(this);   }   frmProcess::~frmProcess() {     delete ui; } //in each timer tick event, we get the latest list of running processes void frmProcess::OnTimerTick() {     LatestProcessList.clear();     LatestProcessList.append(GetAllRunningProcesses());       if(ui->checkBox->isChecked())     {         //getting new processes which are not in the white-list         GetDifference();     }    ui->listWidget->addItems(GetAllRunningProcesses());       //Filling model! in order to avoid flickering!-- this doesnt help!      model->setStringList(LatestProcessList);      ui->listView->setModel(model);   }   //This is where we create a white-list out of our latest running process list void frmProcess::on_pushButton_clicked() {    // GetAllRunningProcesses();     WhiteList.clear();     ui->listWidget_2->clear();       WhiteList.append(GetAllRunningProcesses());     ui->listWidget_2->addItems(WhiteList); } //This method gets the list of all running processes QList<QString> frmProcess::GetAllRunningProcesses() {     HANDLE hSysSnapshot = NULL;     PROCESSENTRY32 proc;       QList<QString> list;     proc.dwSize = sizeof(proc);     hSysSnapshot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 );     Process32First(hSysSnapshot,&proc);     proc.dwSize = sizeof(proc);       ui->listWidget->clear();     list.clear();       do     {         list.append(QString::fromWCharArray(proc.szExeFile));     } while(Process32Next(hSysSnapshot,&proc));       CloseHandle( hSysSnapshot );     return list; }   void frmProcess::GetDifference() {    QSet<QString> intersection = LatestProcessList.toSet().subtract(WhiteList.toSet());    ui->listWidget_3->clear();    ui->listWidget_3->addItems(intersection.toList()); }   void frmProcess::on_btnStartTimer_clicked() {     if(ui->btnStartTimer->text()=="Start")     {         timer->start(1);         ui->btnStartTimer->setText("Stop");     }     else     {         timer->stop();         ui->btnStartTimer->setText("Start");     } }

Viewing all articles
Browse latest Browse all 13965

Trending Articles