溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

c++中Qt容器窗口怎么用

發(fā)布時(shí)間:2021-11-25 09:23:58 來(lái)源:億速云 閱讀:275 作者:小新 欄目:編程語(yǔ)言

這篇文章主要介紹c++中Qt容器窗口怎么用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

容器(Container)

Qt里提供多種容器窗口:

1、選項(xiàng)卡窗口 QTabWidget

2、堆疊窗口  QStackedWidget

3、工具窗口  QToolBox 

一、選項(xiàng)卡窗口

容納多個(gè)子窗口,每個(gè)子窗口顯示一個(gè)標(biāo)簽(選項(xiàng)卡)。當(dāng)標(biāo)簽被點(diǎn)擊時(shí),此窗口置于最前。

實(shí)現(xiàn)方式:

1、使用Qt Designer

2、手動(dòng)添加 Widget

c++中Qt容器窗口怎么用

二、堆疊窗口

容納多個(gè)Widget,每個(gè)Wdiget稱為一頁(yè)

沒(méi)有標(biāo)簽,由其他窗口控制

通??梢宰鱿?qū)С绦?/p>

顯示第幾頁(yè): setCurrectIndex();

小練習(xí):做一個(gè)這樣的界面:

c++中Qt容器窗口怎么用

Test9_2a_12_9::Test9_2a_12_9(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	assert(
		connect(
			ui.btnPage1,
			SIGNAL(clicked()),
			this,
			SLOT(OnBtnPage1())
			)
		);
	assert(
		connect(
			ui.btnPage2,
			SIGNAL(clicked()),
			this,
			SLOT(OnBtnPage2())
			)
		);
	assert(
		connect(
			ui.btnPage3,
			SIGNAL(clicked()),
			this,
			SLOT(OnBtnPage3())
			)
		);
}

int Test9_2a_12_9::OnBtnPage1()
{
	ui.stackedWidget->setCurrentIndex(0);
	return 0;
}

int Test9_2a_12_9::OnBtnPage2()
{
	ui.stackedWidget->setCurrentIndex(1);
	return 0;
}

int Test9_2a_12_9::OnBtnPage3()
{
	ui.stackedWidget->setCurrentIndex(2);
	return 0;
}

三、工具窗口

容納多個(gè)Widget,每個(gè)Wdiget稱為一頁(yè)

小練習(xí):

做如下的界面

c++中Qt容器窗口怎么用

c++中Qt容器窗口怎么用

c++中Qt容器窗口怎么用

實(shí)現(xiàn)代碼:

Test9_3a_12_9::Test9_3a_12_9(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	assert(
		connect(
			ui.btnName,
			SIGNAL(clicked()),
			this,
			SLOT(OnBtnName())
			)
		);
	assert(
		connect(
			ui.btnPasswd,
			SIGNAL(clicked()),
			this,
			SLOT(OnBtnPasswd())
			)
		);
	assert(
		connect(
			ui.btnLogin,
			SIGNAL(clicked()),
			this,
			SLOT(OnBtnLogin())
			)
		);
}

int Test9_3a_12_9::OnBtnName()
{
	ui.stackedWidget->setCurrentIndex(0);
	return 0;
}

int Test9_3a_12_9::OnBtnPasswd()
{
	ui.stackedWidget->setCurrentIndex(1);
	return 0;
}

int Test9_3a_12_9::OnBtnLogin()
{
	ui.stackedWidget->setCurrentIndex(2);
	return 0;
}

以上是“c++中Qt容器窗口怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI