代码:
mVerticalScrollbar = new QScrollBar(this); mHorizontalScrollbar = new QScrollBar(this); mHorizontalScrollbar->setOrientation(Qt::Horizontal);
执行结果:
OnCreate: mVerticalScrollbar( 100 , 30 )
OnCreate: mHorizontalScrollbar( 100 , 30 )
OnResize: mVerticalScrollbar( 100 , 30 )
OnResize: mHorizontalScrollbar( 100 , 30 )
OnShow: mVerticalScrollbar( 13 , 60 )
OnShow: mHorizontalScrollbar( 60 , 13 )
结论:
Qt在Widget创建时期获取Scrollbar的高度和宽度是不准确的,在创建后的Resize时获取的高宽依然不准确,只有在showEvent才能获取到正确的高宽。