QTabWidget是Qt中的標簽類,由於可切換到標簽存在,大大的提高了軟件可容納的控件的數量,通過增加標簽,我們幾乎有用之不盡的空間,那么我們來看看這個類的一些基本用法:
聲明控件:
QTabWidget *twidget;
切換標簽的響應函數:
void YourClass::on_twidget_currentChanged(int idx) { // Implement here if (idx == 0) { // TO DO } else if (idx == 1) { // TO DO } }
別忘了在頭文件中加入私有槽的聲明:
private slots: void YourClass::on_twidget_currentChanged(int idx);
在代碼中切換顯示標簽,0為第一個標簽,1為第二個:
twidget.setCurrentIndex(0); twidget.setCurrentIndex(1);