主要通过如下红色代码的方法实现
效果图片如下:
代码如下:
void MainWindow::createDockWindows()
{
QDockWidget *dock = new QDockWidget(tr("Customers"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
customerList = new QListWidget(dock);
customerList->addItems(QStringList()
<< "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
<< "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
<< "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
<< "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
<< "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
<< "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
dock->setWidget(customerList);
addDockWidget(Qt::RightDockWidgetArea, dock);
viewMenu->addAction(dock->toggleViewAction());
QDockWidget * dock1 = new QDockWidget(tr("Paragraphs"), this);
paragraphsList = new QListWidget(dock1);
paragraphsList->addItems(QStringList()
<< "1"
<< "2 "
<< "4"
<< "5"
<< "6"
<< "7");
dock1->setWidget(paragraphsList);
addDockWidget(Qt::RightDockWidgetArea, dock1);
viewMenu->addAction(dock1->toggleViewAction());
tabifyDockWidget(dock, dock1);
QDockWidget *dock2 = new QDockWidget(tr("Paragraphs"), this);
addDockWidget(Qt::RightDockWidgetArea, dock2);
viewMenu->addAction(dock2->toggleViewAction());
tabifyDockWidget(dock1, dock2);
QDockWidget *dock3 = new QDockWidget(tr("whb"), this);
addDockWidget(Qt::RightDockWidgetArea, dock3);
viewMenu->addAction(dock3->toggleViewAction());
tabifyDockWidget(dock2, dock3);
dock->raise();
connect(customerList, SIGNAL(currentTextChanged(QString)),
this, SLOT(insertCustomer(QString)));
connect(paragraphsList, SIGNAL(currentTextChanged(QString)),
this, SLOT(addParagraph(QString)));
}