Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android: Changing Image on centralWidget() freezes surface
Qt 6.11 is out! See what's new in the release blog

Android: Changing Image on centralWidget() freezes surface

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 1 Posters 358 Views 1 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.
  • T Offline
    T Offline
    TheoSys
    wrote on last edited by
    #1

    Hi,

    I'm developing an application for the Linux desktop as well as Android devices. While I use Qt 6.4 for Linux, I must use Qt 5.15.2 for Android (Qt 6 does not seem to support Android yet). However. Even Qt 5.15.2 works as expected on Linux desktop. My program currently supports both versions of Qt.
    It is necessary to change the background image of the central widget from time to time. This works well on Linux desktop and the application does what it should do.
    The same code on an Android device freezes the surface at the moment I change the image of the central widget. In the background everything is working and the threads are still running. I can click the buttons and they work. But the surface remains frozen and doesn't react any more.
    Here is a small code snippet of how I change the image:

    void MainWindow::setBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color)
    {
    [...]
            QPixmap pix(obj->width, obj->height);
            mBackgroundColor = QColor::fromRgba(qRgba(TColor::getRed(color),TColor::getGreen(color),TColor::getBlue(color),TColor::getAlpha(color)));
            pix.fill(mBackgroundColor);    // Up to here everything works even on Android
    
            if (image.size() > 0)
            {
                QImage img((unsigned char *)image.data(), width, height, rowBytes, QImage::Format_ARGB32);
    
                if (isScaled())
                    pix.convertFromImage(img.scaled(obj->width, obj->height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));  // Freezes on Android!!
                else
                    pix.convertFromImage(img);
            }
    
            QPalette palette;
            palette.setBrush(QPalette::Window, QBrush(pix));
            centralWidget()->setPalette(palette);
            centralWidget()->show();
    [...]
    }
    

    If I just fill the image with any color everything works even on Android. The background get the wanted color and shows it. Any previous image is gone. At the moment I have an image and set this image to the central widget, the surface freezes.

    In which order the above code is called:

    1. The first time on startup the code works even on Android and the image is visible in the background as expected.
    2. When calling the setup (internal custom setup), the background is filled with white color. This works even on Android and the surface remains functional.
    3. Ending the setup: The previous image is set again to the central widget. At this point the surface freezes on Android. Pressing the square button to get all running programs as icons and selecting my application refreshes the surface and I can see it correct. But it's still frozen.
    4. Entering the setup again fills the background with white color. At this moment the surface works again. The setup is full functional even on Android.

    So the problem seems to be with an image only and only on Android.

    Of course I checked the image I got from another library in raw format and it is the one I expect. On Linux this works well.

    Has anybody made a similar experience? Does anybody know what I'm doing wrong? I was not able to find a solution. Maybe somebody knows the problem or at least a workaround.

    BTW: You can see the whole code at Github.

    A.T.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TheoSys
      wrote on last edited by
      #2

      To give you a clue what I mean I made a small video showing the problem on an Android device. Klick here to see the video: Android bug

      BTW: In the meantime I found out that if I set centralWidget()->setAutoFillBackground(false) it is working but then I get a black background only.

      A.T.

      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