Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Ошибка QImage(QImage::setPixel: Index out of range)
Форум на CrossPlatform.RU > Библиотеки > Qt > Qt GUI
demaker

Пытаюсь по нажатию кнопки мыши подкрасить точку, но выдается в консоль ошибка(предупреждение)
Image::setPixel: Index число out of range


Вроде все правильно делаю :huh:
Помогите разобраться
Вот код
GraphicsSceneObstanovka::GraphicsSceneObstanovka(QObject *parent):
    QGraphicsScene(parent)
{
    //addPixmap(QPixmap(":resource/images/submarine_1500_390.bmp"));
    gs = new GeneralSituation();
    addItem(gs);
    setSceneRect(itemsBoundingRect());
}

GraphicsSceneObstanovka::~GraphicsSceneObstanovka()
{
}

//-----------------------------------------------------------------------------------------
GeneralSituation::GeneralSituation(QGraphicsItem *parent):
    QGraphicsObject(parent)
{
    image = new QImage(":resource/images/submarine_1500_390.bmp");
}

GeneralSituation::~GeneralSituation()
{

}

QRectF GeneralSituation::boundingRect() const
{
    return QRectF(0,0,submarina_width,submarina_height);
}

void GeneralSituation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->save();
    painter->drawImage(0,0,*image);
    painter->restore();
}

void GeneralSituation::mousePressEvent(QGraphicsSceneMouseEvent* event)
{

    qDebug()<<"mousePressEvent";

    QPointF scenePoint = event->scenePos();                                            
    qDebug()<<"scenePoint = "<<scenePoint;
    PointColor startPoint;
    startPoint.X = (unsigned int)(scenePoint.x());
    startPoint.Y = (unsigned int)(scenePoint.y());

    delete image;                                                                      
    image = new QImage(":resource/images/submarine_1500_390.bmp");
    image->setPixel(startPoint.X,startPoint.Y,0x00FFFF00U); //color  0x00FFFF00U

    update();                                                                        
}

Спасибо!
Алексей1153
используй
void QImage::setPixelColor(const QPoint &position, const QColor &color)
demaker
Разобрался.
Оказывается файл-рисунок был монохромный, а и не знал.
Из-за этого и ничего и не получалось.
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.