Skip to content
  • 0 Votes
    7 Posts
    172 Views
    Pl45m4P

    @herocon

    Ok next attempt:

    ui->label->setPixmap(p.scaled(ui->label->size()));

    Each iteration scales the pixmap to current label size and then sets the pixmap to the label.
    By doing this, the size of the label increases with the pixmap (because of border/frame... IIRC 1px per side by default, so 2px in total).
    Then you take the new label size again in the next iteration and apply this new (by 2px) increased size to the pixmap... the label gets the pixmap, grows by about 2px in height and there you have your loop where your label and consequently the whole widget grows ;-)

    So still no bug :)
    And it's exactly the behavior you would expect from the debug output.
    (The height increases by 2 each timer interval).
    When using another layout setup, the layout/other widgets might "buffer" that, so the main app window does not grow.
    But even there, the label itself should definitely grow when you periodically set content which has the exact same size as the outter boundings of the label.
    Why though?!

    Try (not tested):

    int w = ui->label->width(); int h = ui->label->height(); ui->label->setPixmap(p.scaled(w - 2, h - 2)); // or this and set the pixmap only once ui->label->setScaledContents(true);

    Because a label with w=500, h=500 for example, can't display a pixmap with w=500, h=500. If you set a pixmap with the same size as the label itself, it will start to grow.

  • 0 Votes
    3 Posts
    2k Views
    P

    Sounds great, but I get some runtime error:

    QPainter::begin: Paint device returned engine == 0, type: 2 QWidget::render: Cannot render with an inactive painter

    Edit:
    There is some modification on your suggested code neccessary:

    const QModelIndex& index = currentIndex(); // Render the pixmap QPixmap pixmap(visualRect(index).size()); //pixmap. render(&pixmap, QPoint(), visualRect(index)); // Create the drag QDrag* drag = new QDrag(this); drag->setPixmap(pixmap); ...

    But anyhow it renders the cell of one index above the selected one.
    Maybe that has something to do with the offset parameter (second one in render).

    Edit2:
    The proper QRect can be calculated with the height of the horizontal header:

    render(&pixmap, QPoint(0,0), visualRect(index).translated(0, horizontalHeader()->height() ));
  • 0 Votes
    7 Posts
    5k Views
    kshegunovK

    @Donn
    There's no way to loselessly convert 16 bit integers into 8 bit integers, so you can't use QImage to display your image without dropping some of the information. I advise to follow @SGaist's advice and research what OpenGL provides and if that will suit your needs.

    PS.
    Please don't post multiple times the same question! I see tree distinct instances of you asking the same thing over and over again in a few hours period.
    http://forum.qt.io/topic/64650/display-2d-array-of-type-uint16-as-grayscale-image
    http://forum.qt.io/topic/64657/display-uint16-image