Qt实现窗口跳转(类似于看图软件中下一张和上一张)
生活随笔
收集整理的這篇文章主要介紹了
Qt实现窗口跳转(类似于看图软件中下一张和上一张)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在UI設計師中添加StackedWidget控件,如下圖:
在窗口中添加兩個按鈕,分別命名為NextButton和PrevousButton。然后右鍵點擊轉到槽,分別把槽函數實現為下面的形式:
void MainWindow::on_PreviousButton_clicked()//上一個按鈕對應的槽函數 {int ncount = this->ui->stackedWidget->count();//求出StackedWidget的總頁面數int current = this->ui->stackedWidget->currentIndex(); //求出當前頁面的索引(此處的索引范圍類似于數組下標,都是0到n-1)current = (current-1+ncount) % ncount;//循環顯示this->ui->stackedWidget->setCurrentIndex(current);this->ui->stackedWidget->update(); //更新stackWidget // this->ui->stackedWidget->show(); //show函數也可以實現更新界面}void MainWindow::on_NextButton_clicked() //下一個按鈕對應的槽函數 {int ncount = this->ui->stackedWidget->count();int current = this->ui->stackedWidget->currentIndex();current = (current+1+ncount) % ncount;this->ui->stackedWidget->setCurrentIndex(current);this->ui->stackedWidget->update();}分別對StackedWidget中的頁面進行不同的設置用以進行區分對比。StackedWidget默認是兩頁,覺著不夠可以鼠標右鍵點擊插入頁。
另外要注意QT中的MainWindow和Ui::MainWindow,這兩貨到底是不是同一個類,如果不是,它倆到底分別指的是什么玩意兒。目前我也不知道準確的答案,哪位大佬若知道準確答案歡迎 指教,鄙人感激不盡。
參鏈接:https://www.cnblogs.com/ourran/p/6691769.html
總結
以上是生活随笔為你收集整理的Qt实现窗口跳转(类似于看图软件中下一张和上一张)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: htaccess文件,强大的功能
- 下一篇: jieba