Results 1 to 12 of 12

Thread: can the image be displayed as it is in chips prog..

  1. #1
    Join Date
    Nov 2008
    Posts
    52
    Qt products
    Qt4
    Platforms
    Windows

    Default can the image be displayed as it is in chips prog..

    Can somebody please tell me if the image can be displayed as it is in chips program.Here image is displayed as chips instead of the original image.After doing zoom-out the original image appears.The chip program's path is:\Qt\4.4.3\demos\chip.The code is :
    void MainWindow::populateScene()
    {
    scene = new QGraphicsScene;

    QImage image(":/img_2.png");

    // Populate scene
    int xx = 0;
    int nitems = 0;
    for ([color=blue]int i = -11000; i < 11000; i += 110) {
    ++xx;
    int yy = 0;
    for (int j = -7000; j < 7000; j += 70) {
    ++yy;
    qreal x = (i + 11000) / 22000.0;
    qreal y = (j + 7000) / 14000.0;

    QColor color (image.pixel (int (image.width () * x), int (image.height () * y)));
    QGraphicsItem *item = new Chip(color, xx, yy);
    item->setPos(QPointF(i, j));
    scene->addItem(item);

    ++nitems;
    }
    }
    }
    Last edited by sh123; 3rd February 2009 at 11:56. Reason: reformatted to look better

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can the image be displayed as it is in chips prog..

    I'm not sure if I understand you correctly. Do you want to achieve the same effect as in chips demo? If yes, then just copy the demo code.

  3. #3
    Join Date
    Nov 2008
    Posts
    52
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: can the image be displayed as it is in chips prog..

    Thanks for responding.No i don't want to achieve the same effect as in chips demo.When we run the chips demo we see the chips(that is,the image in the zoomed form).I want that the image be displayed as it is instead of zoomed one.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can the image be displayed as it is in chips prog..

    So you just want to display an image as a single item?

  5. #5
    Join Date
    Nov 2008
    Posts
    52
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: can the image be displayed as it is in chips prog..

    yes I want to display image as a single item.

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can the image be displayed as it is in chips prog..

    Then have a look at QLabel::setPixmap and if u want to use graphics view, have a look at QGraphicsPixmapItem
    Hope it helps

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can the image be displayed as it is in chips prog..

    Quote Originally Posted by sh123 View Post
    yes I want to display image as a single item.
    Then use QGraphicsPixmapItem as aamer4yu said. Chips demo doesn't show any pixmaps --- it shows only chips.

  8. #8
    Join Date
    Nov 2008
    Posts
    52
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: can the image be displayed as it is in chips prog..

    Thanks very much for the help...I have one more query that I have used Q3ScrollView & displayed an image in it using QLabel.I want to scroll the image.so I tried using QSlider.the QSlider is coming behind the image(that is,QLabel).

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can the image be displayed as it is in chips prog..

    Quote Originally Posted by sh123 View Post
    I have one more query that I have used Q3ScrollView & displayed an image in it using QLabel.
    Use QScrollArea instead and you don't need QSlider, because scroll area/view already has scroll bars. You just have to set it up the right way. There is an example in the docs.

  10. #10
    Join Date
    Nov 2008
    Posts
    52
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: can the image be displayed as it is in chips prog..

    Thanks again.I saw the documentation & used the following code:

    Qt Code:
    1. QLabel *imageLabel = new QLabel;
    2. QImage image("happyguy.png");
    3. imageLabel->setPixmap(QPixmap::fromImage(image));
    4.  
    5. scrollArea = new QScrollArea;
    6. scrollArea->setBackgroundRole(QPalette::Dark);
    7. scrollArea->setWidget(imageLabel);
    To copy to clipboard, switch view to plain text mode 
    Compiler gave the following error :
    canvas.cpp:372: warning: statement has no effect
    canvas.cpp:442: error: `scrollArea' undeclared (first use this function)
    canvas.cpp:442: error: (Each undeclared identifier is reported only once for eac
    h function it appears in.)
    mingw32-make[1]: *** [tmp/obj/debug_shared/canvas.o] Error 1
    mingw32-make[1]: Leaving directory `D:/Qt/4.4.3/examples/graphicsview/portedcanv
    as'
    mingw32-make: *** [debug-all] Error 2

  11. #11
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can the image be displayed as it is in chips prog..

    U dont seem to have declared scrollArea
    Declare it as - QScrollArea * scrollArea = new QScrollArea

  12. #12
    Join Date
    Nov 2008
    Posts
    52
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: can the image be displayed as it is in chips prog..

    Yes now I declared scrollArea.Compiler is not giving error now.but in the output neither scrollarea is seen nor label(image) is seen.

Similar Threads

  1. QSlider custom handle image not displayed
    By planglois in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2008, 13:49
  2. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  3. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  4. no image displayed on QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2007, 12:33
  5. JPEG Image isn't displayed!?
    By GodOfWar in forum Qt Programming
    Replies: 9
    Last Post: 16th April 2007, 15:01

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.