Qt Pen Cosmetic Value Has No Effect



  • I am trying to make a waves diagram that can scale well with the QGraphics View widget. In my current implementation though pen.setCosmetic(true) does not change the fact that my lines become bloated/are not a constant width. Is it not possible to have a constant line width when you're using the ui->GraphicsViewObject->scale()? Could it have something to do with needing pointers?

    here is my code for setting up the pixmap

     QPixmap pixmapWaves(xSize,ySize);
                QPainter painter(&pixmapWaves);
                QBrush backgroundBrush = painter.background();
                backgroundBrush.setColor(Qt::white);
                painter.setBackground(backgroundBrush);
                painter.fillRect(0, 0, xSize, ySize, painter.background() );
                QPen pen(Qt::black);
                pen.setCosmetic(true);
                pen.setWidth(0);
                painter.setPen(pen); //sets pen to the color the wave will be drawn in
    

    here is part of the draw waves loop for brevity

    
     for(uint16_t wavesDrew = 0; wavesDrew < numTracesInFile; wavesDrew++ ) // dividing by 10 is for spee dwhen debugging
                {
    
                    newYval = (1.0*sampleIntervalTimeData*MICRO_TO_MILLI)+20;
                    previousYval = newYval;
                    newXval = centerOfTraceXAxisTracker; //this line combined with previousXval = newXval, sets the x position of the first line, of each trace,
                                                         //to zero relative from the trace center axis
                    painter.drawLine(newXval, newYval, newXval, (numSamplesPerTrace*sampleIntervalTimeData*MICRO_TO_MILLI)+20 );
    
    


  • @brazz said in Qt Pen Cosmetic Value Has No Effect:

    QPen pen(Qt::black);

    Hi! I think this is a bug. Replace it with QPen pen(QColor(Qt::black));.



  • New line works, but the cosmetic is still an issue


  • Qt Champions 2016

    @brazz
    Normally
    pen.setCosmetic(true); or pen.setWidth(0) works
    Im wondering if its because you draw it to a pixmap.
    Its the whole pixmap you scale and not the actual lines`?



  • @mrjj
    Initially there was just two ValueChanged() slots, for horizontal and vertical sliders, that used the changed values to scale the whole graphics view. Thinking now it might actually just work better if I just use the .scaled() method instead of using the scaling in graphics view. Not entirely sure how I would do this. I know I can use graphicsview.scene() to return the scene and scene.graphicsViewItem() to return the item and work with that. There is not a graphicsViewItem.Pixmap() function though, so I'm not entirely sure how I would go about doing this. Any Ideas?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.