void IntroduceForm::initData() { WidgetMain *p = qobject_cast<WidgetMain *>(parentWidget()); EditScene *pScene = p->getScenePointer(); //pScene->setListWidgetIntroducePointer(listWidget); QStringList listComponentsName = getComponentsName("./resource/Blocks/"); connect(listWidget, SIGNAL(signalHideSubWindows()), this, SIGNAL(signalHideSubWindows())); connect(listWidget, SIGNAL(signalShowSubWindows()), this, SIGNAL(signalShowSubWindows())); //填充ListWidget的数据 int itemIndex = 0; foreach (QString bbName, listComponentsName) { qDebug() << bbName; QString name = pHash_moduelName_dataStruct_->value(bbName).ui.name; QString type = pHash_moduelName_dataStruct_->value(bbName).ui.type; //根据type来判断是否是自己关心的类型 if(type_ != type) { continue; } QImage image; QByteArray imageData = pHash_moduelName_dataStruct_->value(bbName).description.imageData; QString description = pHash_moduelName_dataStruct_->value(bbName).description.text; image.loadFromData(imageData, "PNG"); if(imageData.isEmpty()) { qDebug() << "数据库中没有图片数据"; } ListWidgetItemWidget_Component *pItemWidget = new ListWidgetItemWidget_Component(name, listWidget); pItemWidget->setEnabledHoverEvent(true); pItemWidget->setIntroduceInfor(QPixmap::fromImage(image), description); connect(pItemWidget, SIGNAL(signalIntroduce(QPixmap,QString)), this, SLOT(slotIntroduce(QPixmap,QString))); ListWidgetItem *pItem = new ListWidgetItem(pItemWidget); pItem->setData(Qt::UserRole, itemIndex++); pItem->setData(Qt::UserRole+1, name); pItem->setData(Qt::UserRole+2, description); pItem->data_ = pHash_moduelName_dataStruct_->value(bbName); //解决了左边icon右边Widget的问题 pItem->setSizeHint(QSize(41, 31)); listWidget->addItem(pItem); listWidget->setItemWidget(pItem, pItemWidget); }
void MsmWindow::addPageWidget( PageWidget& page ) { // Add list widget item ListWidgetItem* item = new ListWidgetItem( ui->listWidget ); item->setText( page.getTitle() ); item->setIcon( QIcon( page.getIcon() ) ); item->setSizeHint( QSize( 135, 100 ) ); item->page = &page; // Add to stacked widget ui->stackedWidget->addWidget( &page ); connect( &page, &PageWidget::setApplyEnabled, this, &MsmWindow::setApplyEnabled ); connect( &page, &PageWidget::closePage, this, &MsmWindow::closePageRequested ); }