Solved Search the layout of a widget
-
I have a QWidget and I want to know its layout.
I try this but it doesn't work.QVBoxLayout *layout = (QVBoxLayout *)widget->parentWidget()->layout();
It's my window : black squares are layout, and two widgets separated by a splitter who contain them.
I know the first widget and I want to know its layout: the big black square.
Somebody know?Ps : Sorry if I post a lot of subject in the forum but I begin to learn Qt the last week.
-
I have something but with some bugs too :/
I have to save a configuration for example that :
How can I do with QSettings for save all these data ? I have this :QSettings settings("settings.ini", QSettings::IniFormat); settings.setValue("MainWindow/geometry", window->saveGeometry()); settings.setValue("MainWindow/state", window->saveState()); settings.setValue("MainWindow/nbrTabbedWindow", tabbed.size()); for (int i = 0; i < tabbed.size(); i += 1) { QString path = "MainWindow/TabbedWindow/" + QString::number(i); settings.beginGroup(path.toStdString().c_str()); settings.setValue("splitter/geometry", tabbed[i]->splitter->saveGeometry()); settings.setValue("splitter/state", tabbed[i]->splitter->saveState()); settings.setValue("containerWidget/geometry", tabbed[i]->containerWidget->saveGeometry()); settings.setValue("nbrWindows", tabbed[i]->windows.size()); for (int j = 0; j < tabbed[i]->windows.size(); j += 1) { QString pathWindowGeo = "/windows" + QString::number(j) + "/geometry"; QString pathWindowSta = "/windows" + QString::number(j) + "/state"; QString pathContentTextGeo = "/contents" + QString::number(j) + "/text/geometry"; QString pathContentTextTxt = "/contents" + QString::number(j) + "/text/text"; QString pathContentWidgetGeo = "/contents" + QString::number(j) + "/widget/geometry"; QString pathContentWidgetSty = "/contents" + QString::number(j) + "/widget/styleSheet"; settings.setValue(pathWindowGeo.toStdString().c_str(), tabbed[i]->windows[j]->saveGeometry()); settings.setValue(pathWindowSta.toStdString().c_str(), tabbed[i]->windows[j]->saveState()); settings.setValue(pathContentTextGeo.toStdString().c_str(), tabbed[i]->contents[j]->text->saveGeometry()); settings.setValue(pathContentTextTxt.toStdString().c_str(), tabbed[i]->contents[j]->text->text()); settings.setValue(pathContentWidgetGeo.toStdString().c_str(), tabbed[i]->contents[j]->widget->saveGeometry()); settings.setValue(pathContentWidgetSty.toStdString().c_str(), tabbed[i]->contents[j]->widget->styleSheet()); } settings.endGroup(); }
But There are not other ways more simple?
And with my method, I cannot for the moment save splitter's children -
Hi,
Why do you want to know the layout of the parent of your widget ?
-
for remove this widget and apply another widget
-
Then you are doing it from the wrong place.
Can you explain what exactly you want to achieve with your application ?
-
I have for beginning à QMainWindow.
I apply to them à QWidget.
At this QWidget, I apply a QVBoxLayout
At this QVBoxLayout, I apply a QWidget named ContentPanel.
What I Want is when my mouse is on a widget named ContentPanel, the layout of this widget remove this widget, I create another QWidget named ContentPanel, and I apply at those ContentPanel a QSplitter.
I have now 2ContentPanel separated by a QSplitter
If I selected the other QWidget named ContentPanel, it has to do the same.My program has to do this at infinite
(Sorry for my English again ^^')
-
You want to add a new widget each time you hover over any of them ?
-
@SGaist Yes, separated by a QSplitter
-
Can you explain why ?
-
It's for my job, I'm student
-
I meant: why do you want to have new widgets created as soon as you hover over one of them ? Because it means that each time your mouse cursor goes over any of them there's a new one that's going to appear so it can very quickly becomes a mess.
-
I saw this post : https://forum.qt.io/topic/84616/replacing-a-widget-with-another-one-containing-splitter/3
I want to do like him, look at this picture :
Evert box have to be separated by a splitter. But I don't know how to apply at one box two splitters... :/
I know that I can apply container with QVBoxLayout and QWidget but I don't know how to do what I want with that -
Ok, click is not the same as hover and definitely less dangerous in terms of accidental widget explosion. What will the "clicked widget" contain ?
-
Yes ^^
The "clicked widget" is a class TabbedWindow
But It's the same that QWidget. -
Then you have to either implement an event filter to listen to the mouse press event on all of these widgets, or re-implement the
mousePressEvent
of your TabbedWindow and emit a signal that specify which region was clicked so you can connect to it and add new widgets appropriately. -
I have already connect buttons and event but I don't know how create splitters between two tabbed window correctly
-
I have something but with some bugs too :/
I have to save a configuration for example that :
How can I do with QSettings for save all these data ? I have this :QSettings settings("settings.ini", QSettings::IniFormat); settings.setValue("MainWindow/geometry", window->saveGeometry()); settings.setValue("MainWindow/state", window->saveState()); settings.setValue("MainWindow/nbrTabbedWindow", tabbed.size()); for (int i = 0; i < tabbed.size(); i += 1) { QString path = "MainWindow/TabbedWindow/" + QString::number(i); settings.beginGroup(path.toStdString().c_str()); settings.setValue("splitter/geometry", tabbed[i]->splitter->saveGeometry()); settings.setValue("splitter/state", tabbed[i]->splitter->saveState()); settings.setValue("containerWidget/geometry", tabbed[i]->containerWidget->saveGeometry()); settings.setValue("nbrWindows", tabbed[i]->windows.size()); for (int j = 0; j < tabbed[i]->windows.size(); j += 1) { QString pathWindowGeo = "/windows" + QString::number(j) + "/geometry"; QString pathWindowSta = "/windows" + QString::number(j) + "/state"; QString pathContentTextGeo = "/contents" + QString::number(j) + "/text/geometry"; QString pathContentTextTxt = "/contents" + QString::number(j) + "/text/text"; QString pathContentWidgetGeo = "/contents" + QString::number(j) + "/widget/geometry"; QString pathContentWidgetSty = "/contents" + QString::number(j) + "/widget/styleSheet"; settings.setValue(pathWindowGeo.toStdString().c_str(), tabbed[i]->windows[j]->saveGeometry()); settings.setValue(pathWindowSta.toStdString().c_str(), tabbed[i]->windows[j]->saveState()); settings.setValue(pathContentTextGeo.toStdString().c_str(), tabbed[i]->contents[j]->text->saveGeometry()); settings.setValue(pathContentTextTxt.toStdString().c_str(), tabbed[i]->contents[j]->text->text()); settings.setValue(pathContentWidgetGeo.toStdString().c_str(), tabbed[i]->contents[j]->widget->saveGeometry()); settings.setValue(pathContentWidgetSty.toStdString().c_str(), tabbed[i]->contents[j]->widget->styleSheet()); } settings.endGroup(); }
But There are not other ways more simple?
And with my method, I cannot for the moment save splitter's children