修改了ElementPool

TaoZhang-Branch
yang.yongquan 2023-03-08 12:40:05 +08:00
parent 368eaa6c89
commit 1118dc819a
3 changed files with 29 additions and 4 deletions

View File

@ -70,6 +70,9 @@
<QtUic Include="MainWindow.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="EditorWidget.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Editor\EditorWidgetItem.cpp">

View File

@ -3,14 +3,22 @@
ElementPoolWidget::ElementPoolWidget(QWidget* parent)
: QWidget(parent)
{
iconWidth = 150, iconHeight = 100;
parentSize = QSize(270, 210);
elementManager = nullptr;
iconWidth = 80, iconHeight = 60;
pictureList = new QListWidget(this);
pictureList->setIconSize(QSize(iconWidth, iconHeight));
pictureList->setResizeMode(QListView::Adjust);
pictureList->setViewMode(QListView::IconMode);
pictureList->setMovement(QListView::Static);
pictureList->setSpacing(10);
pictureList->setFixedSize(600, 800);
pictureList->setSpacing(5);
pictureList->setStyleSheet("QListWidget::Item:hover{background-color:rgba(47,46,46,0);border-radius:5px; }"
"QListWidget::item:selected{background-color:rgba(47,46,46,0);color:rgb(61,61,61);border:1px solid #000;border-radius:2px; }"
"QScrollBar:vertical{width:6px}");
pictureList->setFocusPolicy(Qt::NoFocus);
pictureList->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
//pictureList->setFixedSize(600, 800);
setVisible(true);
@ -37,13 +45,19 @@ void ElementPoolWidget::setElementList(std::vector<GraphicElement*> elements) {
//p->show();
QListWidgetItem* pItem = new QListWidgetItem(
itemPixmap.scaled(QSize(iconWidth-20, iconHeight-20)),
itemPixmap.scaled(QSize(iconWidth-15, iconHeight-15)),
elements[index]->name);
pItem->setSizeHint(QSize(iconWidth, iconHeight));
pictureList->insertItem(index, pItem);
}
}
void ElementPoolWidget::setParentSize(QSize pSize) {
parentSize = pSize;
iconWidth = (parentSize.width() - 30) / 3;
iconHeight = (parentSize.width() - 30) / 4;
}
ElementPoolWidget::~ElementPoolWidget() {
}
@ -58,4 +72,9 @@ void ElementPoolWidget::setElementManager(ElementManager* element)
{
this->elementManager = element;
this->setElementList(this->elementManager->elements);
}
void ElementPoolWidget::refresh() {
this->setElementList(this->elementManager->elements);
// update();
}

View File

@ -12,12 +12,14 @@ private:
std::vector<GraphicElement*> elements;
QListWidget* pictureList;
int iconWidth, iconHeight;
QSize parentSize;
ElementManager* elementManager;
public:
ElementPoolWidget(QWidget* parent = nullptr);
void setElementList(std::vector<GraphicElement*> elementList);
void setElementManager(ElementManager* element);
void setParentSize(QSize pSize);
~ElementPoolWidget();
signals:
@ -25,5 +27,6 @@ signals:
public slots:
int pictureItemClicked(QListWidgetItem* item);
void refresh();
};