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?
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.
1 Attachment(s)
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?
Attachment 7591
Code:
MainWindow()
{
layout->addWidget(text);
widget->setLayout(layout);
setCentralWidget(widget);
}
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?
Re: How to let the close icon of QWidget on the right-up corner appear?
Quote:
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.
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.
Re: How to let the close icon of QWidget on the right-up corner appear?
try QMainWindow/QMdiArea and friends.
1 Attachment(s)
Re: How to let the close icon of QWidget on the right-up corner appear?
Ok,I explain my question in detail.
Quote:
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)
Attachment 7593
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:
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);
....
Re: How to let the close icon of QWidget on the right-up corner appear?
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.
2 Attachment(s)
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?
Attachment 7600 Attachment 7601
Re: How to let the close icon of QWidget on the right-up corner appear?
You won't know unless you try.
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?
Re: How to let the close icon of QWidget on the right-up corner appear?
Re: How to let the close icon of QWidget on the right-up corner appear?
I paste part of my test code
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);
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.
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?
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.
1 Attachment(s)
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?
Attachment 7606
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).