Results 1 to 6 of 6

Thread: Pan/Move QPixmap in QLabel

  1. #1
    Join Date
    Aug 2014
    Posts
    11
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question Pan/Move QPixmap in QLabel

    Hi,

    First of all, I have seen similar questions in this forum, but I didn't find the answers I was looking for (or maybe I didn't understand the solution).
    Ok, now to the question -
    I have a QLabel, whose size and location (coordinates) are fixed, and I need to display a image in it. This image can be zoomed/width fitted/page fitted/original view, and if the image is larger than the QLabel, I need to give options to move the image on press of some up/down/left/right QButtons. (exact scenario is that after a Scan, preview image is displayed on our panel, and that needs to be zoomed/panned)

    I have been able to do the zoom stuff by using scaled/scaledToWidth/scaledToHeight, but I am having problems in moving/panning the image (QPixmap).

    This is my code for down button

    Qt Code:
    1. mut->lock(); //mutex, just for some test
    2. QRegion exposed;
    3. const QPixmap *p1=label->pixmap(); //label is the QLabel object. This is more of a hit and trial code, and this part was giving some compilation issue with constructor, so the code is written like this
    4. QPixmap *p=new QPixmap(*p1);
    5. p->scroll(0,-10,label->rect(),&exposed);
    6. label->setPixmap(*p);
    7. mut->unlock();
    To copy to clipboard, switch view to plain text mode 

    But the problems I am getting are that
    1) when I press buttons fast, there is some sort of banding (part of image repeating on one end).
    2) I cannot specify any offset using the scroll function, as the image is scrolled only in the QPixmap rect area (not the QLabel area). So the image is not actually moved to the offset. I have attached screenshot for the same

    qpixmap.jpg

    Can someone let me know a better way to do this image panning? (My base QLabel cannot be moved or resized, as that is the preview area)

    Thanks in advance
    Ash

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Pan/Move QPixmap in QLabel

    Why does it have to be QLabel and not e.g. QGraphicsView? BTW. What is the mutex for? Why so many memory leaks?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2014
    Posts
    11
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pan/Move QPixmap in QLabel

    Quote Originally Posted by wysota View Post
    Why does it have to be QLabel and not e.g. QGraphicsView? BTW. What is the mutex for? Why so many memory leaks?
    This was just a hit and trial code. Actually in my working environment (in fedora), I can't run QT Creator for some reasons. So, before writing the code there, I have a random project in QT Creator in Windows where I first try a logic out, and once I get the result, I move the code to linux environment in my project.
    Mutex was just a trial code, as I mentioned that if I pan the image fast then image gets weird with some banding. (as shown in the image above).
    While writign the actual code I will delete the pointers created.

    Regarding QGraphicsView, till now what I have seen in that is QGraphicsView has a solid white background (didn't try it out if transparent widget can be created or not). Basically, the above zoom/pan requirement for me is only in the preview cases. In other cases, I just want to display an image on the panel without any border, and the image can be non-rectangular itself (for example, the image of printer which has the 2D shape of a printer.). So I was worried that if I use QGraphicsView, a white background will be seen below the image.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Pan/Move QPixmap in QLabel

    Maybe you should state the general idea of what you are doing? Maybe your whole app should be implemented in Graphics View? The background can be changed, that is not a problem, the real problem you are going to have anyway is that the top-most widget will handle all mouse input so no events will go to underlying widgets if you want to have any.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2014
    Posts
    11
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pan/Move QPixmap in QLabel

    Quote Originally Posted by wysota View Post
    Maybe you should state the general idea of what you are doing? Maybe your whole app should be implemented in Graphics View? The background can be changed, that is not a problem, the real problem you are going to have anyway is that the top-most widget will handle all mouse input so no events will go to underlying widgets if you want to have any.
    Thanks for your inputs. I am right now trying the code with Graphics view.
    We are in initial phase of our design, and right now we are concentrating on displaying the screens. I guess event handling will work fine as in my sample app, even when a QLabel was on top of QPushButton, the slot for clicked() of QPushButton was called when we clicked it. In any case, if later on I face such issues, I will come back here again for that.

    We are basically designing a LCD panel display of a large MFP (Printer like those Xerox machines). Earlier we were using PEG, but since PEG is quite limited, we are moving to QT and so we are tasked with the porting.

    Edit: If I have forgotten to say it yet wysota, I really appreciate your replies. They are quick and makes me do some analytical thinking.
    Last edited by ashtray4241; 13th August 2014 at 17:26.

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pan/Move QPixmap in QLabel

    Quote Originally Posted by ashtray4241 View Post
    We are basically designing a LCD panel display of a large MFP (Printer like those Xerox machines). Earlier we were using PEG, but since PEG is quite limited, we are moving to QT and so we are tasked with the porting.
    Do you mean something like this: http://wirthconsultingb4youbuy.files...hscreen-jp.jpg
    I don't know your exact requirements but I would consider:
    1. QGraphicsView for this task if the whole project idea suits better to widgets then to QtQuick
    2. QtQuick if you want some nice UI like on the screenshot I've pasted. If your device is OpenGL capable, then you can use QtQuick 2 (which is available in Qt >= 5.0) with QtQuick.Controls and stunning animations and so on if there is no OpenGL then you can still use QtQuick 1 (which is no OpenGL accelerated so you should check the performance, but if you do not want any fancy animations, than it should work fine)
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. How to move QPixmap in QTableView
    By Borland in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2012, 08:38
  2. Replies: 3
    Last Post: 10th April 2011, 15:55
  3. how to move the image in QLabel
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 13th October 2010, 08:33
  4. DrawLine over QPixmap within Qlabel
    By Qt Coder in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2009, 12:21
  5. Rotate QPixmap set on QLabel
    By Qt Coder in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2009, 12:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.