加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
classifierselectorlist.cpp 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
ZzqiZQute 提交于 2018-11-21 22:47 . 201811212247
#include "classifierselectorlist.h"
#include "classifierselector.h"
#include <QListWidgetItem>
#include <QMouseEvent>
#include <QDebug>
#include <QColorDialog>
ClassifierSelectorList::ClassifierSelectorList(QWidget *)
{
mColors<<"#F61B00"
<<"#FEFF29"
<<"#1B00FC"
<<"#F99017"
<<"#50FF29"
<<"#7B00FD";
}
ClassifierSelectorList::~ClassifierSelectorList()
{
}
void ClassifierSelectorList::addItemByNum(int num)
{
QListWidgetItem *item=new QListWidgetItem(this);
this->addItem(item);
//this->setItemWidget(item,new ClassifierSelector(num,QColor(QColor::colorNames()[num%QColor::colorNames().count()])));
this->setItemWidget(item,new ClassifierSelector(num,QColor(mColors[num])));
item->setSizeHint(QSize(0,55));
}
void ClassifierSelectorList::removeItem()
{
this->takeItem(this->count()-1);
}
ClassifierSelector* ClassifierSelectorList::getItem(int row)
{
return static_cast<ClassifierSelector*>(this->itemWidget(this->item(row)));
}
void ClassifierSelectorList::setColorByIndex(int idx, QColor color)
{
ClassifierSelector* item=static_cast<ClassifierSelector*>(this->itemWidget(this->item(idx)));
item->setColor(color);
emit colorChanged(idx,color.rgb());
item->update();
}
void ClassifierSelectorList::mouseDoubleClickEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
{
if(this->itemAt(event->pos())!=nullptr)
{
int row=this->row(this->itemAt(event->pos()));
QColor color=QColorDialog::getColor();
if(color.isValid())
{
setColorByIndex(row,color);
}
}
}
}
void ClassifierSelectorList::mousePressEvent(QMouseEvent *event)
{
if(this->itemAt(event->pos())==nullptr)
{
setCurrentRow(-1);
}
QListWidget::mousePressEvent(event);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化