楼主:
checkIO (chec)
2016-12-02 12:01:17开发平台(Platform): (Ex: Win10, Linux, ...)
vs 2015
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
qt5.7
问题(Question):
http://imgur.com/2K3zM0Q
我目前用了QSlier
我想请问有没有办法写额外两个button去控制pageup and down呢(图片的红框处)
(因为Slier的卷轴我之后要隐藏它)
我目前的写法如下,但这样要自己去算每个widget的间距 非常麻烦
请问有没有更好的办法呢
connect(btnArrowRight, SIGNAL(released()), this, SLOT(moveControllerBox()));
//连结button
void myclass::moveControllerBox() {
QPushButton *btn = qobject_cast<QPushButton *>(sender());
QScrollBar *horizontalScrollBar = listWidget->horizontalScrollBar();
int value = listWidget->horizontalScrollBar()->value();
int movePosition = 0;
if (btn->objectName() == "ArrowLeft") {
if (value - 100 < 0) movePosition = 0;
else movePosition = value - 100;
}
else if (btn->objectName() == "ArrowRight") {
if (value + 100 > 1020) movePosition = 1020;
else movePosition = value + 100;
}
horizontalScrollBar->setSliderPosition(movePosition);
}
作者:
uranusjr (â†é€™äººæ˜¯è¶…級笨蛋)
2016-12-02 12:27:00看不太懂你想要怎样的效果, 可以给个能直接编译的专案吗所以你想要的是模拟 QScrollBar 那两个按钮的功能?(顺带一提 QScrollBar 并不是 QSlider, 请不要混用)那个换页的距离可以直接从 pageStep 里拿到, 不用自己算详细请参照 QAbstractSlider 的文件如果你只是要同样的功能, triggerAction 或许更方便如果内建的 action 不合用那么这样就差不多 OK 了