Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 611

How to get rid of listview and listWidgets flickering?

$
0
0

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 there is a lot 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 processesvoid 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 doesn't help!     model->setStringList(LatestProcessList);     ui->listView->setModel(model);}//This is where we create a white-list of our latest running process listvoid 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 processesQList<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 611

Trending Articles