我一直在寻找互联网,我找不到任何解决方案,所以我有一个像这样的酒吧:
(带有处理程序图片的滚动条)
但是当我通过另一个滚动图片时会发生什么:
有没有办法停止在悲伤的脸上画出悲伤的脸?
这是paintEvent
方法
void QSlider::paintEvent(QPaintEvent* e)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
if (ori_==Qt::Horizontal)
{
if(index>=0)
{
this->setFixedSize(42,57);
printf("\n");
QString dir="C:\\Qt\\Qt5.2.1\\Tools\\QtCreator\\bin\\pluginss\\";
QString emo=QString::fromStdString(emotions.at(index));
dir.append(emo);
dir.append(".png");
QPixmap pixmap(dir);
painter.drawPixmap(QPoint(0,0), pixmap.scaled(40,40, Qt::KeepAspectRatio));
QRect rec(0,22,40,40);
painter.drawText(rec,Qt::AlignCenter,emo);
}
else
{
this->setFixedSize(10,20);
QRect rec(0,7,8,8);
painter.drawRect(rec);
QPolygon pp;
pp << QPoint(0,7) << QPoint(4,0) << QPoint(8,7);
painter.drawPolygon(pp, Qt::OddEvenFill);
}
}
}
这是我的mouseMoveEvent
:
void QSliderWidget::mouseMoveEvent(QMouseEvent* e)
{
if (activeSlider_>=0)
{
QRect crec = contentsRect();
qreal pos;
crec.adjust(rampeditor_->bspace_,0,-rampeditor_->bspace_,0);
pos = 1.0*(e->pos().x()-rampeditor_->bspace_)/(crec.width());
if (pos<0.0 || pos>1.0)
{
delete(rampeditor_->sliders_[activeSlider_]);
rampeditor_->sliders_.removeAt(activeSlider_);
activeSlider_ = -1;
rampeditor_->updateRamp();
}
else
{
rampeditor_->sliders_[activeSlider_]->move(0,e->pos().y());
seconds.replace(activeSlider_-1,e->pos().x());
qSort(rampeditor_->sliders_.begin(), rampeditor_->sliders_.end(), QColorRampEditor::SliderSort);
index=activeSlider_-1;
rampeditor_->mergeSort(0,seconds.size());
}
}
}