功能:
1、可以在收縮欄插件中添加界面
2、可以把界面展開或收縮
3、可以用鼠標(biāo)拖動(dòng)界面改變界面的排放順序
源碼放在最下方
1、可以在收縮欄插件中添加界面
virtual void addWidget(QWidget* widget, const QString& label, const QIcon& icon = QIcon());
參數(shù)1:插入的界面指針
參數(shù)2:插入的界面標(biāo)題
參數(shù)3:插入的界面圖標(biāo)
demo:
在收縮欄插件中添加兩個(gè)界面
//創(chuàng)建收縮欄對象,這里是用插件形式讀取CollpasePagePlugin.dll拿到QObject指針在強(qiáng)轉(zhuǎn)為CollpasePagePlugin對象
//如果不清楚插件用法可以直接new一個(gè)CollpasePagePlugin對象
CollpasePagePlugin* collpasePagePlugin = PluginCore::getinstance()->GetPlugin<CollpasePagePlugin>("CollpasePagePlugin", "MTFTool");
if (collpasePagePlugin)
{
collpasePagePlugin->GetWidget()->setParent(ui.groupBox); //設(shè)置父窗體
collpasePagePlugin->GetWidget()->setMouseTracking(true); //設(shè)置鼠標(biāo)追蹤
collpasePagePlugin->GetWidget()->parentWidget()->setMouseTracking(true); //設(shè)置父窗體鼠標(biāo)追蹤
collpasePagePlugin->SetLayout((QVBoxLayout*)ui.groupBox->layout(), -1); //對收縮欄插件設(shè)置布局
//創(chuàng)建一個(gè)widget
m_MTFSetting = new MTFSetting(this);
//把widget添加到收縮欄
collpasePagePlugin->addWidget(m_MTFSetting, "MTFSetting", QIcon(":/Gen2WGMTFTester/images/MTF/MTFsetting.png"));
//創(chuàng)建另一個(gè)widget
m_ledWidget = new LEDControl(this);
//把widget添加到收縮欄
collpasePagePlugin->addWidget(ledPlugin->GetWidget(), "LEDControl", QIcon(":/Gen2WGMTFTester/images/MTF/LED.jpg"));
//設(shè)置在程序運(yùn)行后兩個(gè)界面默認(rèn)是收縮狀態(tài)
collpasePagePlugin->setItemExpand(0, false);
collpasePagePlugin->setItemExpand(1, false);
}
文章來源:http://www.zghlxwxcb.cn/news/detail-753451.html
2、界面展開或收縮文章來源地址http://www.zghlxwxcb.cn/news/detail-753451.html
3、鼠標(biāo)拖動(dòng)界面移動(dòng)和改變順序源碼下載

到了這里,關(guān)于《QT從基礎(chǔ)到進(jìn)階·三十六》QWidget實(shí)現(xiàn)收縮欄的效果的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!