Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Pen Cosmetic Value Has No Effect
Forum Updated to NodeBB v4.3 + New Features

Qt Pen Cosmetic Value Has No Effect

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brazz
    wrote on last edited by brazz
    #1

    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 );
    
    
    ? 1 Reply Last reply
    0
    • B brazz

      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 );
      
      
      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @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));.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        brazz
        wrote on last edited by
        #3

        New line works, but the cosmetic is still an issue

        mrjjM 1 Reply Last reply
        0
        • B brazz

          New line works, but the cosmetic is still an issue

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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`?

          B 1 Reply Last reply
          0
          • mrjjM mrjj

            @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`?

            B Offline
            B Offline
            brazz
            wrote on last edited by
            #5

            @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?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved