<Qt5> How to refresh two widgets simultaneously by overriding paintEvent
-
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(); } -
When you need a redraw, you should call update()