Results 1 to 4 of 4

Thread: show widget over other widgets

  1. #1
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default show widget over other widgets

    Hi.

    how can I show one widget over others in MainWindow class?

    i have vertical layout with three lists. When I click item i would like to show() widget with some info and button "Close". When i click it widget is Hide();

    I write addWidget() but it's change layout and all moving up.

    Thanks.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: show widget over other widgets

    You need to create QDialog and instead of show(); you need exec(); (witch will make the dialog modal)

  3. #3
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: show widget over other widgets

    Thank You it is ok but....

    When I write :

    Qt Code:
    1. QDialog *ms;
    2.  
    3. MainWindow::MainWindow(QWidget *parent) :
    4. QMainWindow(parent),
    5. ui(new Ui::MainWindow)
    6. {
    7. ....
    8.  
    9. ms = new QDialog();
    10. ms->setWindowOpacity(0.5);
    11. ms->setWindowFlags(Qt::Popup);
    12. ms->exec(); // or show() it's no matter
    To copy to clipboard, switch view to plain text mode 

    in my function, I got error -1073741819 while build

    also for code :

    Qt Code:
    1.  
    2. MainWindow::MainWindow(QWidget *parent) :
    3. QMainWindow(parent),
    4. ui(new Ui::MainWindow)
    5. {
    6. ....
    7.  
    8. ms.setWindowOpacity(0.5);
    9. ms.setWindowFlags(Qt::Popup);
    10. ms.exec(); // or show() it's no matter
    To copy to clipboard, switch view to plain text mode 

    it's runtime C++ error while run application.

    I am newbie and i don't know how to do it, to show dialog when i click button

    edit:
    I need to have global variable ms
    when i write QDialog ms; inside function it's ok. but it's not satisfied for me.
    Last edited by maston; 22nd June 2010 at 22:49.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: show widget over other widgets

    Try this: from Qt Creator, create an Empty Project, add a C++ source file to the project, and write this code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char** argv){
    5. QApplication ap(argc, argv);
    6.  
    7. QWidget *w = new QWidget(0);
    8. QVBoxLayout *l = new QVBoxLayout(w);
    9. QPushButton *b1 = new QPushButton("Open Dialog");
    10. QPushButton *b2 = new QPushButton("Close");
    11. l->addWidget(b1);
    12. l->addWidget(b2);
    13.  
    14. QDialog *dlg = new QDialog(w);
    15. QPushButton *b3 = new QPushButton("Close", dlg);
    16.  
    17. QObject::connect(b1, SIGNAL(clicked()), dlg, SLOT(exec())); //here you can "play" with the show or exec to see the difference
    18. QObject::connect(b2, SIGNAL(clicked()), &ap, SLOT(quit()));
    19. QObject::connect(b3, SIGNAL(clicked()), dlg, SLOT(close()));
    20.  
    21. w->show();
    22.  
    23. return = ap.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    And to not be "off-topic" in your little code that you posted there are two problems
    first: ms = new QDialog(this); (to give the dialog a parent) and make sure in the mainwindow.h you have declared the QDialog *ms;
    second: do not call ms.show() (or exec) in the mainwindow constructor, here you will need to connect the clicked signal from the button to the show (or exec) slot of the dialog (read more on signals and slots if you didn't understood them enough)

  5. The following user says thank you to Zlatomir for this useful post:

    maston (24th June 2010)

Similar Threads

  1. Replies: 10
    Last Post: 29th May 2010, 18:42
  2. Replies: 5
    Last Post: 18th April 2010, 23:31
  3. Replies: 0
    Last Post: 2nd February 2010, 09:44
  4. Interview: Show statusbar or other widgets in a view?
    By uiop21 in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2008, 16:51
  5. is it possible to animate sliding widgets on show/hide
    By discostu in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2007, 08:59

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.