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. <Qt5> How to refresh two widgets simultaneously by overriding paintEvent

<Qt5> How to refresh two widgets simultaneously by overriding paintEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 243 Views
  • 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.
  • T Offline
    T Offline
    twiiiilight
    wrote on last edited by
    #1

    Hi everyone,

    Now I am using Qt5 to draw Kline of stocks. Two classes are defined for price bar and volume bar, then I add them to a widget by a QSplitter. However, When I move mouse forward or backward and the price-bar chart updates, the volume-bar section will not repaint simultaneously until I put mouse under volume widget. I tried some ideas, but it didn't work. Many thanks.

    A part of codes like this:

        pvolume = new VolumeBar(this);
        pvolume->setObjectName(tr("volume_bar"));
        pvolume->setFocusPolicy(Qt::StrongFocus);
    
        pkline = new PriceBar(this);
        pkline->setObjectName("price_bar");
        pkline->setFocusPolicy(Qt::StrongFocus);
    
    
        QSplitter *splitterMain = new QSplitter(Qt::Vertical, 0); 
    
        splitterMain->insertWidget(0, pkline);
        splitterMain->insertWidget(1, pvolume);
        splitterMain->setStretchFactor(0, 4);
        splitterMain->setStretchFactor(1, 1);
    

    For pricebar, the paintEvent function is overrided as follows,

    void PriceBar::paintEvent(QPaintEvent *event)
    {
        KLineGrid::paintEvent(event);  // parent of VolumeBar and PriceBar
        drawLine();  // draw price bar
    }
    

    For VolumeBar, it is overrided like this,

    void VolumeBar::paintEvent(QPaintEvent *event)
    {
    
        KLineGrid::paintEvent(event);
        
        drawYtick();  // y axis
        drawVolume();
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      When you need a redraw, you should call update()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      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