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. QGraphicsScenes / View and padding ..... Problem
Forum Updated to NodeBB v4.3 + New Features

QGraphicsScenes / View and padding ..... Problem

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.4k Views
  • 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by gfxx
    #1

    On ubuntu 14.04, QT creator 3.6... I have a QGraphicsView with these style:

    QGraphicsView{color: black; border: 3px solid #5E749C;text-align: top;padding:-4px;border-radius: 7px; border-bottom-left-radius: 7px;background: #cfc;width: 15px; }
    

    I add a Qrect and Qpixmap in these way...

    Graphicsviews-result

    then copy the result of operation into qLabel usig a crop with same dimension of outer qrect in Qgraphicsview ..... but the result is not as I expect ....:

    Copy and crop Graphicsviews-result into QLabel

    I suspect the problem is the padding in Qlabel and Qgraphicsview .... but not understand the logic ...

    my code:

    QBrush brush_red(Qt::red, Qt::Dense5Pattern);
        QPen outline(Qt::black);
        outline.setWidth(1);
        QRect r1(QPoint(0, 0), QSize(75, 95));
        QRect r2(QPoint(0, 0), QSize(75, 95));
        QRect r1_1(QPoint(0, 0), QSize(85, 105));
        QRect r2_1(QPoint(0, 0), QSize(85, 105));
    
        QPixmap bxV("/home/boxcarton-qt.png");
        QPixmap bxH("/home/boxcarton-qt_R.png");
    
    
        QPixmap bxV_scal = bxV.scaled(QSize(75, 95), Qt::IgnoreAspectRatio, Qt::FastTransformation);
        QPixmap bxH_scal = bxH.scaled(QSize(75, 95), Qt::IgnoreAspectRatio, Qt::FastTransformation);
    
        QPixmap bxV_rect = bxV_scal.copy(r1);
        QPixmap bxH_rect = bxH_scal.copy(r2);
    
        QRectF rect_vbox = ui->VBox->sceneRect();
        scene_VBox = new QGraphicsScene(this);
        scene_VBox->setSceneRect(rect_vbox);
        ui->VBox->scale(1, 1);
        ui->VBox->setScene(scene_VBox);
        ui->VBox->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        ui->VBox->fitInView(scene_VBox->sceneRect(),Qt::KeepAspectRatio);
        ui->VBox->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        ui->VBox->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    
    
        QRectF rect_hbox = ui->HBox->sceneRect();
        scene_HBox = new QGraphicsScene(this);
        scene_HBox->setSceneRect(rect_hbox);
        ui->HBox->scale(1, 1);
        ui->HBox->setScene(scene_HBox);
        ui->HBox->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        ui->HBox->fitInView(scene_HBox->sceneRect(),Qt::KeepAspectRatio);
        ui->HBox->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        ui->HBox->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    
    
        rectangle_VBox = scene_VBox->addRect(r1_1, outline, brush_red);
        rectangle_VBox->setPos((110-85)/2, (110-105)/2);
        rectangle_HBox = scene_HBox->addRect(r2_1, outline, brush_red);
        rectangle_HBox->setPos((110-85)/2, (110-105)/2);
        box_VBox = scene_VBox->addPixmap(bxV_rect);
        box_VBox->setPos((110-75)/2, (110-95)/2);
        box_HBox = scene_HBox->addPixmap(bxH_rect);
        box_HBox->setPos((110-75)/2, (110-95)/2);
    
        QRect rect_final(QPoint(int((110-85)/2), int((110-105)/2)), QSize(85, 105));
    
        QPixmap grab_VBox = ui->VBox->grab();
        QPixmap grab_HBox = ui->HBox->grab();
        QPixmap crop_VBox = grab_VBox.copy(rect_final);
    
        ui->VBox_2->setPixmap(crop_VBox);
        ui->VBox_2->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        ui->VBox_2->show();
        ui->VBox_2->setAttribute(Qt::WA_DeleteOnClose);
    
        ui->HBox_2->setPixmap(grab_HBox);
        ui->HBox_2->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        ui->HBox_2->show();
        ui->HBox_2->setAttribute(Qt::WA_DeleteOnClose);
    
    

    bkt

    1 Reply Last reply
    0
    • gfxxG Offline
      gfxxG Offline
      gfxx
      wrote on last edited by gfxx
      #2

      Re: QGraphicsScenes / View and padding ..... Problem

      Make sure to constrain all painting inside the boundaries of boundingRect() to avoid rendering artifacts (as QGraphicsView does not clip the > > painter for you). In particular, when QPainter renders the outline of a shape using an assigned QPen, half of the outline will be drawn outside, > and half inside, the shape you're rendering (e.g., with a pen width of 2 units, you must draw outlines 1 unit inside boundingRect()). QGraphicsItem does not support use of cosmetic pens with a non-zero width.

      So if i use Qpen 1 pixel .... the bounding rect in qgraphicsscene, paint 1px inside and 1px outer ....(obviusly not 0,5 inside and 0,5 outside) ... so QPen border is a problem not padding.....

      other problem depends from the way that I use to draw rect and icon inside a scene...

      For better explain me, using padding into QGraphicsViews is possible but it become part of scene ... so in my case I set 118118 pixel QraphicsView ... than I set into QTCreator GraphicsVievs "scenerect" 110100 px "x=0 y=0" ....... than when crop the image crop it wit offset 4,4 .... so all is well done inseide an area of 110*100 (my search area) than I can copy these image without scale or difference ....

      regards
      Giorgio

      bkt

      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