0

i have an application in qt that loads an image. The user can set a cross by moving the slider with setPixel(). If he decrements the slider, the cross should become smaller and the original pixel should be displayed.

But unfortunately nothing happens when I decrement the slider. The cross keeps its maximum size.

The function, that sets the Pixel

    void ImageViewer::applyExampleAlgorithm(int kreuzBreite)
{
    if(image!=NULL)
    {
       
        for(int i=0;i<((kreuzBreite*std::min(image->width(), image->height())/ 100) / 2);i++)
        {
                         image->setPixelColor(image->width()/2+i,image->height()/2,QColor(255,0,0,0));
                         image->setPixelColor(image->width()/2-i,image->height()/2,QColor(255,0,0,0));
                         image->setPixelColor(image->width()/2,image->height()/2+i,QColor(255,0,0,0));
                         image->setPixelColor(image->width()/2,image->height()/2-i,QColor(255,0,0,0));
            } 
                      }

updateImageDisplay();
    renewLogging();
    }

My Slider

QSlider *slider1 = new QSlider(Qt::Horizontal,0);
    slider1->setRange(0,100);
    connect(slider1, SIGNAL(valueChanged(int)),this, SLOT(applyExampleAlgorithm(int)));

Slider value at 85

Slider value at 26

As you can see, the value changes, but my cross does not.

I think I have to save the original pixel and rewrite it, as soon as the red cross disappears at this point. But I dont really know how.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

When the slider value decreases, your function only "draw" a smaller red cross in the bigger one that was drawn before. You can store the original image in a different variable. Then, before drawing the red cross, restore to the original image.

Minh
  • 1,630
  • 1
  • 8
  • 18