Results 1 to 3 of 3

Thread: setCentralWidget problems

  1. #1

    Question setCentralWidget problems

    Setup: Qt 4.4.3, using visual studio 2005

    I have an app ui file (which is empty) and I want to add another centralWidget UI file on top of it (so when I maximize I can have a black background in my app ui and my centralWidget UI can be center screen. I am trying to use setCentralWidget() for this. If I explained things correctly, is this the path I want to follow? I cant even get a button to display in the central widget:

    Qt Code:
    1. QApp::QApp(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. ui.setupUi(this);
    5. CentralWidget cw;
    6. b.setGeometry(20,20,20,20);
    7. b.setEnabled(true);//.show();
    8. setCentralWidget( &b );
    9. }
    To copy to clipboard, switch view to plain text mode 

    Any help is appreciated. Thank you!

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: setCentralWidget problems

    You should not declare cw and b in the constructor and in the stack, declare them in the class and in the heap, as pointers, because they get out of scope when then constructor method ends.

    Qt Code:
    1. CentralWidget *cw = new CentralWidget;
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: setCentralWidget problems

    Doh! What a n00b error. Thanks for the help!

Similar Threads

  1. Mac OSX OpenGL problems
    By tksharpless in forum Qt Programming
    Replies: 0
    Last Post: 23rd March 2009, 17:27
  2. problems creating toolbar...(do see the attachment)!
    By sumit in forum Qt Programming
    Replies: 15
    Last Post: 10th September 2008, 11:23
  3. flicker and wierd resize problems ...
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2008, 18:00
  4. Problems with setCentralWidget
    By Rockem in forum Qt Programming
    Replies: 21
    Last Post: 8th March 2008, 23:57
  5. Replies: 2
    Last Post: 8th March 2007, 22:22

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.