Results 1 to 2 of 2

Thread: Is Update() the right way?

  1. #1
    Join Date
    Sep 2008
    Posts
    24
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Is Update() the right way?

    Hi all,

    I have a program in which two widgets are connected together. One widget displays an image and upon a mouse event (press) it passes the co-ordinates (in the form of a QPoint) to the other widget. My hope is that this Widget then displays a cropped version of the other image.

    I have so far been unsuccessful in this. My main problem is updating the cropped-image display widget. Currently it shows nothing (the signals and slots are working by the way).

    Here is the code

    Qt Code:
    1. MyWidgetOne::MyWidgetOne(QWidget* parent): QWidget(parent)
    2. {
    3. int x, y;
    4.  
    5. coordOne = new QPoint;
    6.  
    7. drawLabel = new QLabel;
    8. QPixmap dl;
    9. dl.load("resources/image_ori.bmp");
    10. dl = dl.copy(x-25, y-25, 50, 50);
    11. dl.save("resources/image.bmp");
    12. drawLabel->setPixmap(dl);
    13.  
    14.  
    15. QVBoxLayout* mainLayout = new QVBoxLayout;
    16. mainLayout->addWidget(drawLabel);
    17.  
    18. setLayout(mainLayout);
    19. setWindowTitle(tr("Receiver"));
    20. }
    21.  
    22. void MyWidgetOne::showCoords(QPoint xy)
    23. {
    24. int i, j;
    25. coordOne = &xy;
    26. i = (coordOne->x());
    27. j = coordOne->y();
    28. x = i;
    29. y = j;
    30. update();
    31. //repaint();
    32. }
    To copy to clipboard, switch view to plain text mode 

    So as you can see I use x and y to define the corner of the area to be displayed (with a 50 height and width). When I receive the QPoint, I update this values via i and j).

    I thought putting update() or repaint() would work but they have so far been of no use. Any help would be appreciated.

  2. #2
    Join Date
    Sep 2008
    Posts
    24
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is Update() the right way?

    Hey,

    Managed to get it working.

    Qt Code:
    1. void MyWidgetOne::paintEvent(QPaintEvent *event)
    2. {
    3. QPixmap dm;
    4. dm.load("resources/image_ori.bmp");
    5. dm = dm.copy(x-25, y-25, 50, 50);
    6. dm.save("resources/image.bmp");
    7. drawLabel->setPixmap(dm);
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    Forgot to include the above I suppose just writing down the problem reminded me of what was missing!

Similar Threads

  1. Qt Update project - Opinions wanted
    By pvdk in forum Qt Programming
    Replies: 0
    Last Post: 8th November 2008, 08:41
  2. QModelView update
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2008, 22:02
  3. QPainter update()
    By csvivek in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2008, 09:42
  4. immediate update of QT object
    By db in forum Newbie
    Replies: 3
    Last Post: 14th August 2007, 12:25
  5. How to update statusbar and tooltips
    By aamer4yu in forum Qt Programming
    Replies: 9
    Last Post: 21st December 2006, 12:38

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.