Results 1 to 19 of 19

Thread: How to let the close icon of QWidget on the right-up corner appear?

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default How to let the close icon of QWidget on the right-up corner appear?

    I create a widget and add it to a mainwindow,and find that the widget can not be closed,for it has not close icon on its right-up corner appear,how to do?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    only windows have close buttons. widgets with parents are not windows.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    In the constructor function create a widget and put a QTextEdit on it,show as the following code. Now I want to close the widget by click the close icon on its right-up corner and find there is nothing on it. How to do?


    widget.PNG

    Qt Code:
    1. MainWindow()
    2. {
    3. QWidget *widget=new QWidget;
    4. QTextEdit *text=new QTextEdit;
    5. layout->addWidget(text);
    6. widget->setLayout(layout);
    7.  
    8. setCentralWidget(widget);
    9. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by weixj2003ld; 16th April 2012 at 10:57.

  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: How to let the close icon of QWidget on the right-up corner appear?

    I can see a nice big red cross in the upper right corner of the widget, can't you?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    I can see a nice big red cross in the upper right corner of the widget, can't you?
    it is that of mainwindow,and not that of the widget.

  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: How to let the close icon of QWidget on the right-up corner appear?

    Why would you expect each widget to have its own close button? Have you ever seen anything like that? Only dock windows and mdi area subwidgets can be closed separately from the window that owns them since they are considered windows themselves.
    Last edited by wysota; 16th April 2012 at 11:32. Reason: spelling corrections
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    try QMainWindow/QMdiArea and friends.

  8. #8
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    Ok,I explain my question in detail.

    Why would you expect each widget to have its own close button?
    I want to do the following things:
    1.For example,I have 9 child windows,and they arranged in 3 rows 3 lines,show as picture.(Maybe I have more than many child windows)
    windows.PNG
    2.I want to close each child window respectively.
    3.If I double click one of them,it is floating.(that is,it can be out of the mainwindow)
    4. I want them to zoom in or zoom out together.

    So,QMainWindow can not satisfy my need, can it?.

    I use for QSplitter, the oration of one is vertical,those of others are horizonal.
    code:

    Qt Code:
    1. //create widget1,and put a text1 on it,
    2. QSplitter *horizonSpliter1=new QSplitter;
    3. QWidget *widget1=new QWidget;
    4.  
    5. QTextEdit *text1=new QTextEdit;
    6. QHBoxLayout *layout1=new QHBoxLayout;
    7. layout1->addWidget(text1);
    8. widget1->setLayout(layout1);
    9.  
    10. //create widget2,and put a text2 on it,
    11. QWidget *widget2=new QWidget;
    12. QTextEdit *text2=new QTextEdit;
    13. QHBoxLayout *layout2=new QHBoxLayout;
    14. layout2->addWidget(text2);
    15. widget2->setLayout(layout2);
    16.  
    17.  
    18. //create widget3,and put a text3 on it,
    19. QWidget *widget3=new QWidget;
    20. QTextEdit *text3=new QTextEdit;
    21. QHBoxLayout *layout3=new QHBoxLayout;
    22. layout3->addWidget(text3);
    23. widget3->setLayout(layout3);
    24.  
    25. // insert widget1,widget2,widget3 into horizonSpliter1
    26. horizonSpliter1->insertWidget(0,widget1);
    27. horizonSpliter1->insertWidget(1,widget2);
    28. horizonSpliter1->insertWidget(2,widget3);
    29.  
    30.  
    31. //Does thing about horizonSpliter2 is the same as that of horizonSpliter1.
    32. QSplitter *horizonSpliter2=new QSplitter;
    33. QWidget *widget4=new QWidget;
    34. QTextEdit *text4=new QTextEdit;
    35. QHBoxLayout *layout4=new QHBoxLayout;
    36. layout4->addWidget(text4);
    37. widget4->setLayout(layout4);
    38.  
    39. QWidget *widget5=new QWidget;
    40. QTextEdit *text5=new QTextEdit;
    41. QHBoxLayout *layout5=new QHBoxLayout;
    42. layout5->addWidget(text5);
    43. widget5->setLayout(layout5);
    44.  
    45. QWidget *widget6=new QWidget;
    46. QTextEdit *text6=new QTextEdit;
    47. QHBoxLayout *layout6=new QHBoxLayout;
    48. layout6->addWidget(text6);
    49. widget6->setLayout(layout6);
    50.  
    51. horizonSpliter2->insertWidget(0,widget4);
    52. horizonSpliter2->insertWidget(1,widget5);
    53. horizonSpliter2->insertWidget(2,widget6);
    54.  
    55.  
    56.  
    57.  
    58. //Does thing about horizonSpliter3 is the same as that of horizonSpliter1.
    59. QSplitter *horizonSpliter3=new QSplitter;
    60. QWidget *widget7=new QWidget;
    61.  
    62. QTextEdit *text7=new QTextEdit;
    63. QHBoxLayout *layout7=new QHBoxLayout;
    64. layout7->addWidget(text7);
    65. widget7->setLayout(layout7);
    66.  
    67. QWidget *widget8=new QWidget;
    68. QTextEdit *text8=new QTextEdit;
    69. QHBoxLayout *layout8=new QHBoxLayout;
    70. layout8->addWidget(text8);
    71. widget8->setLayout(layout8);
    72.  
    73.  
    74. QWidget *widget9=new QWidget;
    75. QTextEdit *text9=new QTextEdit;
    76. QHBoxLayout *layout9=new QHBoxLayout;
    77. layout9->addWidget(text9);
    78. widget9->setLayout(layout9);
    79.  
    80. horizonSpliter3->insertWidget(0,widget7);
    81. horizonSpliter3->insertWidget(1,widget8);
    82. horizonSpliter3->insertWidget(2,widget9);
    83.  
    84.  
    85.  
    86. QSplitter *verticalSpliter=new QSplitter;
    87. verticalSpliter->setOrientation(Qt::Vertical);
    88.  
    89. //insert horizonSpliter1,horizonSpliter2,horizonSpliter3 into verticalSpliter.
    90. verticalSpliter->insertWidget(0,horizonSpliter1);
    91. verticalSpliter->insertWidget(1,horizonSpliter2);
    92. verticalSpliter->insertWidget(2,horizonSpliter3);
    93. ....
    To copy to clipboard, switch view to plain text mode 
    Last edited by weixj2003ld; 17th April 2012 at 03:57.

  9. #9
    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: How to let the close icon of QWidget on the right-up corner appear?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    IMHO it's an odd approach but you can always try Qt::Tool flag.

  11. #11
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    Ok.I will use QDockWidget.
    Can it arrange all dockwidgets like the following pictures?
    docks.png dock3.png
    Last edited by weixj2003ld; 18th April 2012 at 03:51.

  12. #12
    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: How to let the close icon of QWidget on the right-up corner appear?

    You won't know unless you try.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    I have try,and it can not.Could you tell me how to do?
    Last edited by weixj2003ld; 18th April 2012 at 08:47.

  14. #14
    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: How to let the close icon of QWidget on the right-up corner appear?

    What have you tried?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    I paste part of my test code
    Qt Code:
    1. //dock1
    2. QDockWidget *dock = new QDockWidget(tr("dock1"), this);
    3. dock->setAllowedAreas(Qt::AllDockWidgetAreas);
    4. customerList = new QListWidget(dock);
    5. customerList->addItems(QStringList()
    6. << "dock1"
    7. dock->setWidget(customerList);
    8. addDockWidget(Qt::AllDockWidgetAreas, dock);
    9.  
    10. //dock2
    11. dock = new QDockWidget(tr("dock2"), this);
    12. dock->setAllowedAreas(Qt::AllDockWidgetAreas);
    13. paragraphsList = new QListWidget(dock);
    14. paragraphsList->addItems(QStringList()
    15. << "dock2."
    16. dock->setWidget(paragraphsList);
    17. addDockWidget(Qt::AllDockWidgetAreas, dock);
    18.  
    19. //dock3
    20. dock = new QDockWidget(tr("dock3"), this);
    21. dock->setAllowedAreas(Qt::AllDockWidgetAreas);
    22. paragraphsList = new QListWidget(dock);
    23. paragraphsList->addItems(QStringList()
    24. << "dock3."
    25. dock->setWidget(paragraphsList);
    26. addDockWidget(Qt::AllDockWidgetAreas, dock);
    To copy to clipboard, switch view to plain text mode 

    I create three dockwidgets,and setAllowedAreas() of them with the same value Qt::AllDockWidgetAreas(that is,they can be put any side of the mainwindow),and add them into the mainwindow with addDockWidget(Qt::AllDockWidgetAreas, dock),that is,dock them any side at first.

    When the program run,I drag each of them to arrange them like the picture in the last post,but I can not however I drag them.

  16. #16
    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: How to let the close icon of QWidget on the right-up corner appear?

    Did you set a central widget for your main window?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    Thank you for your on-line answer.

    no. Must be set it?
    I want only the dockwidgets,and do not need the central widget.

  18. #18
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to let the close icon of QWidget on the right-up corner appear?

    I have set a central widget(created by QWidget) for the main window,and set its fixed size 1X1(because I do want it to be seen).

    Now,I can arrange the three dock widget like the second picture in the #11 post.

    But the following problem occur.

    When I drag the dock widgets with mouse,I find that there is blank space between them,(I think, it may be the central widget,but I have set the size of it 1X1),could you tell me why?

    blankspace.PNG

  19. #19
    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: How to let the close icon of QWidget on the right-up corner appear?

    Because the dock on the left is attached to the left dock area and the docks on the right are attached to the right dock area. Try forcing all of them to be attached to the left area (by forbidding them from the right area).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 17th November 2011, 11:51
  2. Can't close a QWidget from itself
    By tonnot in forum Newbie
    Replies: 3
    Last Post: 25th August 2011, 10:19
  3. Replies: 1
    Last Post: 18th May 2011, 14:36
  4. How to Disabel close button on top corner of widget
    By jsmith in forum Qt Programming
    Replies: 4
    Last Post: 2nd August 2010, 16:57
  5. Replies: 1
    Last Post: 7th July 2007, 09:03

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.