[問題] QT QSlider控制問題
開發平台(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);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.124.46.66
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1480651280.A.561.html
→
12/02 12:27, , 1F
12/02 12:27, 1F
想用上面的ArrowLeft跟ArrowRight button做到跟SliderBar一樣移動的效果
ArrowLeft的要自己去算 每次要移動的間隔 但不想每次都人工去對齊
但有辦法直接取得Slider按下左右移動效果嗎?
https://drive.google.com/file/d/0B7STNBJf-RECaFI4Z3dkU1lOcVE/view?usp=sharing
這邊是專案
→
12/02 14:23, , 2F
12/02 14:23, 2F
→
12/02 14:23, , 3F
12/02 14:23, 3F
→
12/02 14:24, , 4F
12/02 14:24, 4F
→
12/02 14:24, , 5F
12/02 14:24, 5F
對 因為我想把拉霸隱藏 用按鈕操作
所以取得換頁的距離之後
想使用自制的button去模擬那兩個按鈕的功能還是要自己寫setSliderPosition嗎?
我最後改寫成這樣了 如果有更好的方法麻煩再請指教
void move::moveControllerBox() {
QPushButton *btn = qobject_cast<QPushButton *>(sender());
QScrollBar *horizontalScrollBar = listWidget->horizontalScrollBar();
qDebug()<<"listWidget width: "<<listWidget->width();
int nowScrollValue = listWidget->horizontalScrollBar()->value();
int movePosition = 0;
int singleStep = horizontalScrollBar->singleStep(); //一次跳一格的距離
//int pageStep = horizontalScrollBar->pageStep(); //一次跳整頁的距離
if (btn->objectName() == "ArrowLeft") {
movePosition = nowScrollValue - singleStep;
}
else if (btn->objectName() == "ArrowRight") {
movePosition = nowScrollValue + singleStep;
}
horizontalScrollBar->setSliderPosition(movePosition);
}
※ 編輯: checkIO (210.242.6.98), 12/02/2016 15:05:13
→
12/02 15:11, , 6F
12/02 15:11, 6F
→
12/02 15:12, , 7F
12/02 15:12, 7F
→
12/02 15:58, , 8F
12/02 15:58, 8F
→
12/02 16:22, , 9F
12/02 16:22, 9F
→
12/02 18:22, , 10F
12/02 18:22, 10F
→
12/02 18:30, , 11F
12/02 18:30, 11F
→
12/02 18:31, , 12F
12/02 18:31, 12F
如果是像這個畫面這樣
https://www.youtube.com/watch?v=OJL_484Nct4
假設我有六個item(六張圖) 但我畫面只能容納五個item
0 1 2 3 4 5
初始畫面
0 1 2 3 4
按下向右鍵之後要變成
1 2 3 4 5
再按一次向右
2 3 4 5 0
在按一次向右
3 4 5 0 1 請問這種特效是類似carousel的意思嗎?
感覺QScrollBar做不到?
※ 編輯: checkIO (114.25.217.6), 12/03/2016 19:59:22
→
12/03 20:06, , 13F
12/03 20:06, 13F
→
12/03 20:07, , 14F
12/03 20:07, 14F
→
12/03 20:07, , 15F
12/03 20:07, 15F
→
12/03 21:24, , 16F
12/03 21:24, 16F
→
12/03 21:24, , 17F
12/03 21:24, 17F