how to make QMainWindow not flicker when change size

时间:2018-12-03 13:10:45

标签: qt resize flicker qmainwindow

I display the push flow information of OBS on the QMainWindow object. When I change the size of the QMainWindow window by dragging with the mouse, the window flickers; when I drag the mouse (without changing its size), the window does not flicker. I checked the message through spy++ and found that when I change the window to flash, the system will generate a WM_PAINT message. as fllow enter image description here By looking at Qt's help documentation, I rewrote the function nativeEvent; however, when I judge the WM_PAINT, WM_ERASEBKGND message, the program will fall into an infinite loop

bool MainLayerItemWndView::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
	MSG* msg = (MSG*)message;
	switch (msg->message)
	{
	case WM_PAINT:
		
		std::cout << "nativeEvent paint: " << "message handle1:"  << std::endl;
		*result = 1;
	
		return true;
	break;
	case WM_ERASEBKGND:
		*result = 1;
		std::cout << "WM_ERASEBKGND :---------------" << std::endl;
		return true;
		break;
	default:
		break;
	}
	return QWidget::nativeEvent(eventType, message, result);
}
When I rewrite the eventFilter to intercept the redraw message, the window is still flashing, and I can see the WM_PAINT message in spy++. So, what should I do when I change the size of the QMainWindow window (and OBS will also push), the window will not blink? Or is there any other way to avoid this problem? Thank you very much.

0 个答案:

没有答案