How to get scroll bar real width in Qt?

别说谁变了你拦得住时间么 提交于 2019-12-30 08:37:26

问题


I'm trying to make a custom widget, which is basically a bunch of textedits with a single vertical scroll bar on the right. To keep widget size determined, I have to find a width of the scrollbar, as texedits geometry depends on it. Simply calling scroll_bar->width(); for freshly created vertical bar returns 101, which is obviuosly wrong.

So, is there a way to determine vertical scroll bar width correctly in Qt 3.2.3?


回答1:


int w = qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent);



回答2:


I've also found

vsb->sliderRect().width(); 

which happens to be correct, but it looks bad in the code, as I have no interest in slider per se.



来源:https://stackoverflow.com/questions/16515646/how-to-get-scroll-bar-real-width-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!