Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 552373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:29:34+00:00 2026-05-13T11:29:34+00:00

I am writing an info-screen program. I created a full-screen widget and draw contents

  • 0

I am writing an info-screen program. I created a full-screen widget and draw contents onto it.

In order to extend the life cycle of the TFT-display device, I want to implement a pixel-shifting feature. With other words, in every X minutes, I shift the screen to left/right/top/down for Y pixels.

My approach is as follows:

  1. I use two layers (two QWidget).
  2. I paint contents on the top layer.
  3. When a pixel-shifting is performed, I just move the top layer for specified offset.
  4. And then fill a background color to the bottom layer.

However, I found a problem:

If I move up the top layer for 10 pixels, the 10-pixel-content goes out of the screen. But when I move this layer down for 10 pixels. The 10-pixel-content will not be updated, it is gone.

How can I keep these 10-pixel-content? Is there any magic widget flag to solve this problem?

UPDATE 1:
The code is written in language D, but it is easy to understand:

class Canvas: QWidget
{
    private QPixmap content;

    this(QWidget parent)
    {
        super(parent);
        setAttribute(Qt.WA_OpaquePaintEvent, true);
    }

    public void requestForPaint(QPixmap content, QRegion region)
    {
        this.content = content;
        update(region);
    }

    protected override void paintEvent(QPaintEvent event)
    {
        if (this.content !is null)
        {
            QPainter painter = new QPainter(this);
            painter.setClipping(event.region);
            painter.fillRect(event.region.boundingRect, new QColor(0, 0, 0));
            painter.drawPixmap(event.region.rect, this.content);
            this.content = null;
            painter.setClipping(false);
        }
    }
}

class Screen: QWidget
{
    private Canvas canvas;

    this()
    {
        super(); // Top-Level widget
        setAutoFillBackground(True);
        this.canvas = new Canvas(this);
        showFullScreen();
    }

    public void requestForPaint(QPixmap content, QRegion region)
    {
        this.canvas.requestForPaint(content, region);
    }

    private updateBackgroundColor(QColor backgroundColor)
    {
        QPalette newPalette = palette();
        newPalette.setColor(backgroundRole(), backgroundColor);
        setPalette(newPalette);
    }

    public shiftPixels(int dx, int dy)
    {
        this.canvas.move(dx, dy);
        updateBackgroundColor(new QColor(0, 0, 0)); // Just a demo background color
    }
}

Screen screen = new Screen;
screen.requestForPaint(some_content, some_region);
screen.shiftPixels(0, -10);
screen.shiftPixels(0, 10);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:29:34+00:00Added an answer on May 13, 2026 at 11:29 am

    Looking at the code, my first guess is that your region might be wrong. Try repainting the whole widget each time, and see if that solves the missing 10 pixel problem. If it does, then try working out why your region isn’t covering the newly exposed portion.

    One possibility along those lines: I notice in your Screen::requestForPaint method that you directly call the Canvas::requestForPaint without doing anything with the region. In Qt, the coordinates for anything like that are often assumed to be local, so if you don’t account for the current position of the canvas widget, you might get an incorrect region.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a query to fetch results for all the values in a
I am learning on my own about writing an interpreter for a programming language,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.