Results 1 to 6 of 6

Thread: Best way to add child windows

  1. #1
    Join Date
    Feb 2007
    Posts
    39
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Best way to add child windows

    I've been trying QT4 for the past few days and i'm having problems understanding how the implement this in my application:

    What i want to achieve:

    1) Main window with buttons -OK
    2) User press one of the buttons a Tab widget will appear -OK
    3) Tab Widget have button -OK
    4) User press button on tab widget and a new window must appear on top of the tab widget

    The 4) never works for me, unless i use a QmessageBox, but i really need more "control" over the message window in question.


    I created things like this:

    //Create the tab widget

    Stuff_tab::Stuff_tab(QWidget *parent) : QDialog(parent)
    {

    tabWidget = new QTabWidget;
    tabWidget->addTab(new Tab1, tr("Tab 1"));
    tabWidget->addTab(new Tab2, tr("Tab 2"));

    .......

    mainLayout = new QVBoxLayout;//(this);
    mainLayout->setSizeConstraint( QLayout::SetFixedSize );
    tabWidget->setFixedSize(400, 768);

    mainLayout->addWidget(tabWidget);
    setLayout(mainLayout);

    setWindowTitle(tr("Tab"));
    }




    void Stuff_tab::infoMessage() //called from a button on the tab widget
    {

    QDialogButtonBox *buttonBox; // i also tried with different widget types
    buttonBox = new QDialogButtonBox(QDialogButtonBox::Open
    | QDialogButtonBox::Cancel
    | QDialogButtonBox::Help);


    QVBoxLayout *mainLayout2 = new QVBoxLayout( this );
    mainLayout2->setSizeConstraint( QLayout::SetFixedSize );

    buttonBox->setFixedSize(200, 200);
    mainLayout2->addWidget(buttonBox);

    setLayout(mainLayout2); // use this?
    }
    //this part never show up on screen


    I can't have nested layouts? Am i doing things the wrong way? Any help will be really appreciated. Thanks in advance.

  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: Best way to add child windows

    What exactly do you want to achieve? Have you tried calling show() on widgets which you add after the window is first shown?

  3. #3
    Join Date
    Feb 2007
    Posts
    39
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Best way to add child windows

    Well, as a matter of fact i didn't called show(), which i just did now, the child widget now pops up but under the tab widget, and i only have control over it after i close the tab widget.

  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: Best way to add child windows

    Does "under the tab widget" mean "behind the tab widget" or "lower than the tab widget" (in terms of geometry)?
    Maybe you're just after a modal dialog? In that case wrap the new widget into a QDialog and use QDialog::exec() to pop up a modal dialog.

  5. #5
    Join Date
    Feb 2007
    Posts
    39
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Best way to add child windows

    Quote Originally Posted by wysota View Post
    Does "under the tab widget" mean "behind the tab widget" or "lower than the tab widget" (in terms of geometry)?
    Well, after i press the button on the tab widget, the new window shows up near top left of the screen (not centered with the tab widget) and i can't press on it, i only can after i close the tab widget.

    Quote Originally Posted by wysota View Post
    Maybe you're just after a modal dialog? In that case wrap the new widget into a QDialog and use QDialog::exec() to pop up a modal dialog.
    I understand it in theory, but after browsing through the Qdialog members i couldn't see which will be the correct member to cal for wrapping a widget into Qdialog?

  6. #6
    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: Best way to add child windows

    Qt Code:
    1. QDialog dlg;
    2. QVBoxLayout *l = new QVBoxLayout(&dlg);
    3. MyWidget *wgt = new MyWidget;
    4. l->addWidget(wgt);
    5. dlg.exec()
    To copy to clipboard, switch view to plain text mode 

  7. The following 2 users say thank you to wysota for this useful post:

    Mrdata (3rd February 2007), tpf80 (8th March 2007)

Similar Threads

  1. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00
  2. Replies: 5
    Last Post: 4th August 2006, 23:44
  3. Child windows in QCanvas as a canvas item
    By incubator in forum Qt Programming
    Replies: 8
    Last Post: 18th July 2006, 14:50
  4. Child Windows
    By s_a_white in forum Newbie
    Replies: 1
    Last Post: 16th July 2006, 00:20
  5. MDI windows without QWorkspace
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 16th June 2006, 17:15

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.