Skip to content
  • 0 Votes
    4 Posts
    160 Views
    G

    For the historical record, I finally got it working. My code:

    `

    QRect screenGeometry = QGuiApplication::primaryScreen( )->geometry( ); int x13; int x23; int y13; int y23; if( screenGeometry.width( ) < width( )) { x13 = m_image->getScrollX( ) + screenGeometry.width( ) / 3.0; x23 = m_image->getScrollX( ) + 2 * screenGeometry.width( ) / 3.0; } else { x13 = m_image->getScrollX( ) + width( ) / 3.0; x23 = m_image->getScrollX( ) + 2 * width( ) / 3.0; } if( screenGeometry.height( ) < height( )) { y13 = m_image->getScrollY( ) + screenGeometry.height( ) / 3.0; y23 = m_image->getScrollY( ) + 2 * screenGeometry.height( ) / 3.0; } else { y13 = m_image->getScrollY( ) + height( ) / 3.0; y23 = m_image->getScrollY( ) + 2 * height( ) / 3.0; } QPainter painter( this ); painter.setPen( QPen( Qt::red, 4, Qt::SolidLine, Qt::FlatCap )); painter.drawLine( 0, y13, width( ), y13 ); painter.drawLine( 0, y23, width( ), y23 ); painter.drawLine( x13, 0, x13, height( )); painter.drawLine( x23, 0, x23, height( ));

    }

    `

  • 0 Votes
    14 Posts
    524 Views
    Z

    Is it under x11 or wayland ?

  • 0 Votes
    4 Posts
    316 Views
    G

    I have made continuous attempts and discovered some patterns in color conversion. The official documentation of QCursor mentions Qt::color0 and Qt::color1, which indeed follow certain rules. However, I found that the results I obtained are the opposite of the bit values.

    As mentioned in my comments, I am currently inverting the bit values of the Windows original AND mask and XOR mask to match Qt::color0 and Qt::color1 as mentioned in the QCursor documentation.

    /** * type: MONOCHAROME has (AND bitmap) and (XOR bitmap). * 1 bit = 1 pixed * * Windows: * AND bitmap XOR bitmap Display * 0 0 Black * 0 1 White * 1 0 Screen * 1 1 Reverse screen * * QCursor: * The cursor bitmap (B) and mask (M) bits are combined like this: * B=1 and M=1 gives black. * B=0 and M=1 gives white. * B=0 and M=0 gives transparent. * B=1 and M=0 gives an XOR'd result under Windows, undefined results on all other platforms. * Use the global Qt color Qt::color0 to draw 0-pixels and Qt::color1 to draw 1-pixels in the bitmaps. * * Actual results: * 0 0 Black * 1 0 White * 1 1 transparent screen * 0 1 Reverse screen */ int size = pCursorData->width * pCursorData->height / 2 / 8; if(pCursorData->dataLen / 2 != size) { qWarning() << "[CMouseModule::SetServerCursor] set Cursor Data dataLen failed."; return; } QImage image(pCursorData->width, pCursorData->height / 2, QImage::Format_Mono); QImage maskImage(pCursorData->width, pCursorData->height / 2, QImage::Format_Mono); if(image.sizeInBytes() != size) { qWarning() << "[CMouseModule::SetServerCursor] bitmap size not eq Cursor Data image size."; return; } uchar* imageBits = image.bits(); uchar* maskImageBits = maskImage.bits(); int pitch = pCursorData->dataLen / pCursorData->height; bool andPixel; bool xorPixel; // // `height` is 2 bitmap; for(int y=0; y < pCursorData->height / 2; y++) { for(int x=0; x < pCursorData->width; x++) { quint8 bitMask = 0x80 >> (x % 8); quint8 uint8_x = x / 8; // width is bit size andPixel = pCursorData->pixelData[y * pitch + uint8_x] & bitMask; xorPixel = pCursorData->pixelData[(y + pCursorData->height / 2) * pitch + uint8_x] & bitMask; if(!andPixel && !xorPixel) { imageBits[y * pitch + uint8_x] &= ~bitMask; // 0 maskImageBits[y * pitch + uint8_x] &= ~bitMask; // 0 } else if(!andPixel && xorPixel) { imageBits[y * pitch + uint8_x] |= bitMask; // 1 maskImageBits[y * pitch + uint8_x] &= ~bitMask; // 0 } else if(andPixel && !xorPixel) { imageBits[y * pitch + uint8_x] |= bitMask; // 1 maskImageBits[y * pitch + uint8_x] |= bitMask; // 1 } else if(andPixel && xorPixel) { imageBits[y * pitch + uint8_x] &= ~bitMask; // 0 maskImageBits[y * pitch + uint8_x] |= bitMask; // 1 } } } QBitmap bitmap; QBitmap maskBitmap; bitmap = QBitmap::fromImage(image); maskBitmap = QBitmap::fromImage(maskImage); QCursor cursor(bitmap, maskBitmap, pCursorData->xHotspot, pCursorData->yHotspot); renderWidget->setCursor(cursor);
  • 0 Votes
    7 Posts
    921 Views
    SGaistS

    Animation, composition, overlaying and whatever comes to your imagination.

    That said, if you are really only showing one single image and nothing more then, indeed, a QLabel is enough.

  • 0 Votes
    6 Posts
    2k Views
    SGaistS

    Depending on your end goal, you might want to consider using a library like OpenCV to do the zooming part and Qt to display the result.

  • 0 Votes
    3 Posts
    632 Views
    Guy GizmoG

    I'm afraid that doesn't help for my use case, since I need the images to appear as clear and clean as possible when being scaled down.

  • 0 Votes
    2 Posts
    378 Views
    jsulmJ

    @FarukErat said in I cannot set QPixmap without passing the whole directory:

    I wanna shorten tha path to ":/res/black.bmp".

    Then you need to put them into a resource file: https://doc.qt.io/qt-5/resources.html

  • 0 Votes
    14 Posts
    1k Views
    Christian EhrlicherC

    @Nick-Redwill This is what windeployqt is for...

  • Image showing in QLabel

    Unsolved General and Desktop
    4
    0 Votes
    4 Posts
    527 Views
    Christian EhrlicherC

    @Sai-Raul said in Image showing in QLabel:

    Already tried that

    And what was the outcome? Please update your code accordingly.

  • 0 Votes
    5 Posts
    923 Views
    SGaistS

    Hi,

    You should check your video file, but as I wild guess, it's likely a FullHD video which is 1920 * 1024. Since you are creating a RGB QImage out of it, it's already weighing about 6MB per image. QPixmap is meant to be optimised for rendering and thus the backing memory used might even be larger for, for example, alpha channel handling. Depending on what else you do with your application and these images you can pretty quickly hit memory limits if your application is 32bit.

  • 0 Votes
    7 Posts
    4k Views
    artwawA

    Just let Qt do its work. If by drawing directly on QWidget you mean subclassing it and rewriting its Paint() method - don't do it unless you absolutely have to. Or, when you need to provide a delegate for a view.
    So far I've not had the necessity to dive that deep.
    And since you can display (and scale) images and videos using QLabel, push buttons can be readily supplied with an icon... I just had not need.
    Then again, your needs might differ.

  • 1 Votes
    9 Posts
    2k Views
    I

    Thank you all guys. Your suggestions and expert opinion helped a lot with solving the problem. QT forum is always so helpful.

    After trying many things here is the conclusion and code is now working perfectly fine

    I removed the tic toc part

    time(&start);
    timer = double(getTickCount());
    tic();
    It was working but crashing then just to make sure that QImage is not NULL I removed the img = QImage(); // releasing memory

    with

    if(!img.isNull())
    img = QImage();
    Its working perfectly fine now.

  • 0 Votes
    13 Posts
    2k Views
    M

    @Bonnie
    Thank you very much, it worked perfectly.

  • 0 Votes
    3 Posts
    596 Views
    A

    @Bonnie said in QfileDialog::Getopenfilename does not open the second time and after:

    Remove that static.

    Static local variables

    Variables declared at block scope with the specifier static or thread_local (since C++11) have static or thread (since C++11) storage duration but are initialized the first time control passes through their declaration (unless their initialization is zero- or constant-initialization, which can be performed before the block is first entered). On all further calls, the declaration is skipped.

    So with the static keyword, getOpenFileName will only be called at the first time.

    Thanks! I just realized that I should not have copy pasted that line of code without looking at it closer.

    Cheers.

  • 0 Votes
    3 Posts
    529 Views
    SGaistS

    Hi,

    How did you set the QLabel on your QScrollArea ?

    If you put it in a layout on the scroll area then that's wrong.

  • 0 Votes
    22 Posts
    4k Views
    SGaistS

    Rather than giving the pointer to your MainWindow instance, pass directly the pointer to your label. Basically:

    mainwindow->ui->label
  • 0 Votes
    12 Posts
    906 Views
    SGaistS

    Then maybe QTreeView::drawBranches is what you are looking for.