Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can i stop listview and listWidget from flickering?
Forum Updated to NodeBB v4.3 + New Features

How can i stop listview and listWidget from flickering?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Coderx
    wrote on last edited by
    #1

    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");
    }
    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Technically you are trying to refresh a widget at over 1kHz which is way too fast. What you can do is cache the data and refresh a bit more slowly.

      Also, why trying to go that fast ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Coderx
        wrote on last edited by
        #3

        Hi
        Thanks for the response :)
        the reason i am doing it in such a way is that i need and i want to get the closest time to the realtime events concerning creation of processes.
        lessening that rate would result in un dependable results i.e the list doesnt represent the process lists at all.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          There are no screens out there that can update at 1000 Hz. A typical modern screen can only update at around 60 Hz (once every ~17 ms). See http://www.tweakguides.com/Graphics_7.html

          [quote author="Coderx" date="1387939887"]i need and i want to get the closest time to the realtime events concerning creation of processes.
          lessening that rate would result in un dependable results i.e the list doesnt represent the process lists at all.[/quote]The human eye can't process updates that quickly :)

          Have a look at the Windows Task Manager, which has a table of processes. It updates at only 1 Hz. When I set it to View -> Update Speed -> High, the update rate goes up to 2 Hz. Updating every 500 ms is considered "high speed"!

          [quote author="Coderx" date="1387772591"]
          @
          ui->listWidget_3->clear();
          ui->listWidget_3->addItems(intersection.toList());
          @
          [/quote]
          Destroying and creating new QListWidgetItems every iteration is expensive. Try updating your existing ones using QListWidgetItem::setText() instead. It might help, but I agree with SGaist: Your best solution is still to update the widget less frequently.

          (You can compute a new list every 1 ms, but don't update the widget every 1 ms)

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved