设置QScrollBar的滑块大小与内容相对应 [英] Set slider size of QScrollBar correspond with content

查看:6193
本文介绍了设置QScrollBar的滑块大小与内容相对应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个软件绘图表面代表一个情节(像一个sin函数)(QWidget的一个孩子),我想有一个QScrollBar像QScrollArea。所以如果我的绘图窗口小部件显示750点(我的情节是由点组成),但有1000点,我想滚动条的滑块填充75%的可用空间。



我不能使用QScrollArea,因为滚动是与它包含的小部件的大小成比例。在我的例子中,滚动必须与屏幕上的点数成比例。我知道如何得到我的比率,但我不知道如何正确设置QScrollBar



示例:我编辑了PageStep的值,但我不明白如何这项工作。我可以将pageStep设置为100,范围为[0,99],它将填充QScrollBar的一半。



我的界面:



QWidget(垂直布局)//主窗口小部件
绘图表面(QWidget的子窗口)
QScrollBar(水平)


解决方案

好,我想我可以这样做:



http:/ /harmattan-dev.nokia.com/docs/library/html/qt4/qscrollbar.html




文档长度,范围在滚动条中使用的值,在许多常见情况下页面步骤很简单。滚动条的值范围通过从表示文档长度的某个值减去所选的页面步长来确定。在这种情况下,以下等式是有用的:document length = maximum() - minimum()+ pageStep()。


我的case的长度是点的数量,我可以设置minimum()为0.所以,你可以看到的图片,做一些像QScrollArea。比例为:PercentageVisible = PageStep / Length,另一个方程为Length = PageStep + Max。



我有两个方程,两个缺失值(PageStep和Maximum)值(百分比可见和长度)。



示例:我有1024个点,但只显示其中的75%。



0.75 = PageStep / 1024 ----------> PageStep = 768



1024 = Max + 768 -------- --------> Max = 256



您可以在软件中试用它,它会工作。我知道没有那么多人需要重现这个,因为QScrollArea将在大多数情况下做这个工作。



例如,这个代码是在一个槽反应从调整大小事件:

  ui.sbarRange-> setPageStep(u64SampleCount * dRatio); 
ui.sbarRange-> setMaximum(u64SampleCount - ui.sbarRange-> pageStep());


I am doing a software with a drawing surface that represent a plot (like a sin function) (A child of QWidget) and I would like to have a QScrollBar acting like a QScrollArea. So if my drawing widget show show 750 dots (my plot is made of dots), but there are 1000 dots, I would like the slider of the ScrollBar to fill 75% of the available space.

I can't use a QScrollArea because the scroll is proportionnal with the size of the widget it contains. In my case, the scroll must be proportionnal with the number of dots on the screen. I know how to get my ratio, but I don't know how to setup correctly the QScrollBar

Example: I edited the value of PageStep, but I don't understand how this work. I can set pageStep to 100 with a range of [0,99] and it will fill the half of the QScrollBar.

My interface:

QWidget (Vertical Layout) //Main Widget
    Drawing Surface (Child of QWidget)
    QScrollBar (Horizontal)

解决方案

Well, I think I am able to do something with this:

http://harmattan-dev.nokia.com/docs/library/html/qt4/qscrollbar.html

The relationship between a document length, the range of values used in a scroll bar, and the page step is simple in many common situations. The scroll bar's range of values is determined by subtracting a chosen page step from some value representing the length of the document. In such cases, the following equation is useful: document length = maximum() - minimum() + pageStep().

So in my case the length is the number of dots and I can set minimum() to 0. So, as you can see on the picture, to do something like QScrollArea. The proportion is: PercentageVisible = PageStep / Length and another equation is Length = PageStep + Max.

I have two equations, two missing values (PageStep and Maximum) and two known values (PercentageVisible and Length).

Example: I have 1024 dots, but only 75% of them are shown.

0.75 = PageStep / 1024 ----------> PageStep = 768

1024 = Max + 768 ----------------> Max = 256

You can try it in your software and it will works. I know there's not so much people that will needs to reproduce this because QScrollArea will do the job in most of the case.

By example, this code is in a slot reacting from a resize event:

ui.sbarRange->setPageStep(u64SampleCount * dRatio);
ui.sbarRange->setMaximum(u64SampleCount - ui.sbarRange->pageStep());

这篇关于设置QScrollBar的滑块大小与内容相对应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆