Results 1 to 4 of 4

Thread: Problem with adding picture during running

  1. #1
    Join Date
    Apr 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with adding picture during running

    Hi everybody,

    I have a function which draws a picture on screen :
    Qt Code:
    1. void MainWindow::darwAGate(int x,int y,int gate_code)
    2. {
    3. //load images:
    4. QPixmap *pixmap_and = new QPixmap("../pix/AND.png");
    5.  
    6. QHBoxLayout *h_layout = new QHBoxLayout();
    7. QLabel *label_tmp = new QLabel(this);
    8. label_tmp->setGeometry(x,y,gate_width_pixel,gate_height_pixel);
    9. label_tmp->setPixmap(*pixmap_and);
    10. h_layout->addWidget( label_tmp );
    11. this->setLayout(h_layout);
    12. }
    To copy to clipboard, switch view to plain text mode 


    I have to draw some pix in start of the program, so I like this:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. //draw pics
    8. darwAGate(100, 100, 3);
    9. }
    To copy to clipboard, switch view to plain text mode 

    The on screen i see the pixs. So i dont have any problem till here.

    In the ui I have a bottum which I want to use that for inserting additional pix on screen:

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. // a sample pic :
    4. darwAGate(100, 100, 2);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Unfortunately I don't see any additional pic on screen, when I click on push_bottun.

    Whats wrong?


    Thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem with adding picture during running

    first, is the slot called? second, with setLayout in your draw function, you delete every earlier set layout. So this not not the right way to go!

  3. #3
    Join Date
    Apr 2010
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with adding picture during running

    Quote Originally Posted by Lykurg View Post
    first, is the slot called?
    You mean I click on the bottun? (Yes!)

    second, with setLayout in your draw function, you delete every earlier set layout. So this not not the right way to go!
    Do mean that I can't paint several pics with this function,by deleting previous layout ?
    How do you think I'd better to do ?

    Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem with adding picture during running

    Quote Originally Posted by d@nyal View Post
    You mean I click on the bottun? (Yes!)
    No, I hope you are able to click a button I meant have you checked if the slot is really called. E.g. Put a qWarning() statement in the slot and see if at runtime the message appears or use a debugger to check.
    Do mean that I can't paint several pics with this function,by deleting previous layout ?
    How do you think I'd better to do ?

    Thanks.
    You can, but setGeometry and using a layout is nonsense, since one "overwrites" the other. So in your case you probably want to use only setGeometry. Also you can store the positions in a local member variable and do all the painting in the paint event of your widget.

Similar Threads

  1. problem running application in qvfb
    By maroonmoon in forum Installation and Deployment
    Replies: 0
    Last Post: 25th February 2010, 13:58
  2. Problem in running app on WINCE
    By pinkfrog in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 26th August 2009, 10:33
  3. Problem running QT4.5
    By raghvendramisra in forum Installation and Deployment
    Replies: 3
    Last Post: 6th June 2009, 19:10
  4. problem running Qt4.x binary on Qt3.x
    By raman_31181 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 20th February 2008, 20:02
  5. Replies: 1
    Last Post: 17th May 2006, 00:23

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
  •  
Qt is a trademark of The Qt Company.