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?
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?
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.
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:
MainWindow() { layout->addWidget(text); widget->setLayout(layout); setCentralWidget(widget); }To copy to clipboard, switch view to plain text mode
Last edited by weixj2003ld; 16th April 2012 at 11:57.
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.I can see a nice big red cross in the upper right corner of the widget, can't you?
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 12:32. Reason: spelling corrections
try QMainWindow/QMdiArea and friends.
Ok,I explain my question in detail.
I want to do the following things:Why would you expect each widget to have its own close button?
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:
//create widget1,and put a text1 on it, layout1->addWidget(text1); widget1->setLayout(layout1); //create widget2,and put a text2 on it, layout2->addWidget(text2); widget2->setLayout(layout2); //create widget3,and put a text3 on it, layout3->addWidget(text3); widget3->setLayout(layout3); // insert widget1,widget2,widget3 into horizonSpliter1 horizonSpliter1->insertWidget(0,widget1); horizonSpliter1->insertWidget(1,widget2); horizonSpliter1->insertWidget(2,widget3); //Does thing about horizonSpliter2 is the same as that of horizonSpliter1. layout4->addWidget(text4); widget4->setLayout(layout4); layout5->addWidget(text5); widget5->setLayout(layout5); layout6->addWidget(text6); widget6->setLayout(layout6); horizonSpliter2->insertWidget(0,widget4); horizonSpliter2->insertWidget(1,widget5); horizonSpliter2->insertWidget(2,widget6); //Does thing about horizonSpliter3 is the same as that of horizonSpliter1. layout7->addWidget(text7); widget7->setLayout(layout7); layout8->addWidget(text8); widget8->setLayout(layout8); layout9->addWidget(text9); widget9->setLayout(layout9); horizonSpliter3->insertWidget(0,widget7); horizonSpliter3->insertWidget(1,widget8); horizonSpliter3->insertWidget(2,widget9); verticalSpliter->setOrientation(Qt::Vertical); //insert horizonSpliter1,horizonSpliter2,horizonSpliter3 into verticalSpliter. verticalSpliter->insertWidget(0,horizonSpliter1); verticalSpliter->insertWidget(1,horizonSpliter2); verticalSpliter->insertWidget(2,horizonSpliter3); ....To copy to clipboard, switch view to plain text mode
Last edited by weixj2003ld; 17th April 2012 at 04:57.
IMHO it's an odd approach but you can always try Qt::Tool flag.
I have try,and it can not.Could you tell me how to do?
Last edited by weixj2003ld; 18th April 2012 at 09:47.
I paste part of my test code
Qt Code:
//dock1 dock->setAllowedAreas(Qt::AllDockWidgetAreas); << "dock1" dock->setWidget(customerList); addDockWidget(Qt::AllDockWidgetAreas, dock); //dock2 dock->setAllowedAreas(Qt::AllDockWidgetAreas); << "dock2." dock->setWidget(paragraphsList); addDockWidget(Qt::AllDockWidgetAreas, dock); //dock3 dock->setAllowedAreas(Qt::AllDockWidgetAreas); << "dock3." dock->setWidget(paragraphsList); 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.
Did you set a central widget for your main window?
Thank you for your on-line answer.
no. Must be set it?
I want only the dockwidgets,and do not need the central widget.
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
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).
Bookmarks