Is there a Widget for PyQt5 for Phyton that remove all from layout ?
-
Can you explain a bit more what you UI is about ?
-
This images will explain you better. This is the partial solution code implemented. When user select the radio buttons (after image), then empty all the selection when the user push the cancel button (before image). Will nice to have a widget to empty the layout instead to write the first code in all windows.
-
Hi
When you say reset layouts, do you mean the Widgets to revert to blank input?
LIke uncheck all checkboxes etc ?
Clearing the layout would remove all widgets from screen so that seems a bit overkill
if just to reset the input. -
Hi
When you say reset layouts, do you mean the Widgets to revert to blank input?
LIke uncheck all checkboxes etc ?
Clearing the layout would remove all widgets from screen so that seems a bit overkill
if just to reset the input.@mrjj Yes, you got it.
-
Hi
ok so its reset button and Cancel do not close anything and hence the "old"
value remains.
There is no Widget that can do this for you.
However, you could make a QGroupBox subclass that would add such feature for any
sub widgets it holds. Or simply a global function that takes QWidget *parent and resets all widgets it owns. Note that such function must know how to reset the widgets you have used.
Like setText for LineEdit and setCheck for checkboxes etc. -
Hi
ok so its reset button and Cancel do not close anything and hence the "old"
value remains.
There is no Widget that can do this for you.
However, you could make a QGroupBox subclass that would add such feature for any
sub widgets it holds. Or simply a global function that takes QWidget *parent and resets all widgets it owns. Note that such function must know how to reset the widgets you have used.
Like setText for LineEdit and setCheck for checkboxes etc.@mrjj Thanks for your answer. Will be nice to have a Widget to do so. Maybe we can ask for it to QT.
-
@mrjj Thanks for your answer. Will be nice to have a Widget to do so. Maybe we can ask for it to QT.
@Sergei_Rack
Hi, i think its to broad a topic to get a Qt included Widget as often, people use
other start values than blank and a function to do it is maybe
10-20 lines unless it must handle ALL widget there is. Some are hard(er) to reset. Like
views with models etc. But for LineEdit/textEdit and checkboxes its not super complex.You can use FindChildren (i assume python also have that) and use q_object_cast to
convert to actual type and call the right method for each type to set to blank. -
@mrjj Thanks for your answer. Will be nice to have a Widget to do so. Maybe we can ask for it to QT.
@Sergei_Rack Could you do an example for me, please.
-
@Sergei_Rack Could you do an example for me, please.
Hi
Yes later this evening i can. -
@Sergei_Rack
Hi, i think its to broad a topic to get a Qt included Widget as often, people use
other start values than blank and a function to do it is maybe
10-20 lines unless it must handle ALL widget there is. Some are hard(er) to reset. Like
views with models etc. But for LineEdit/textEdit and checkboxes its not super complex.You can use FindChildren (i assume python also have that) and use q_object_cast to
convert to actual type and call the right method for each type to set to blank.@mrjj said in Is there a Widget for PyQt5 for Phyton that remove all from layout ?:
q_object_cast
There is no equivalent of qobject_cast in PyQt. If you wish to access an overridden superclass method, you must use super.
-
@mrjj said in Is there a Widget for PyQt5 for Phyton that remove all from layout ?:
q_object_cast
There is no equivalent of qobject_cast in PyQt. If you wish to access an overridden superclass method, you must use super.
@Sergei_Rack
oh, i forgot its python
Will a c++ sample works ?
I dont use pyt at all. -
@Sergei_Rack
oh, i forgot its python
Will a c++ sample works ?
I dont use pyt at all.@mrjj Well yes, I try to convert from C++ to Phyton.
-
@mrjj Well yes, I try to convert from C++ to Phyton.
@Sergei_Rack
Hi, ok
I was thinking something likevoid ResetWidgets( QWidget* parent) { QList<QWidget*> children = parent->findChildren<QWidget*>(); foreach (QWidget* widget, children) { //- QLineEdit* LineEdit = qobject_cast<QLineEdit* >(widget); if(LineEdit) { LineEdit ->setText(QString()); continue; } //- QCheckBox* CheckBox = qobject_cast<QCheckBox*>(widget); if(CheckBox) { CheckBox->setChecked(false); continue; } //- QPlainTextEdit* PlainTextEdit = qobject_cast<QPlainTextEdit* >(widget); if(PlainTextEdit) { PlainTextEdit->setPlainText(QString()); continue; } // add more types } }
you could make it far more generic in c++ with templates but im not sure python has
something like it - so i didnt.I cant help with python code but found this
for row in range(layout.rowCount()): for column in range(layout.columnCount()): item = layout.itemAtPosition(row, column) if item is not None: widget = item.widget() if isinstance(widget, QLineEdit): listWidget.addItem(widget.text())
So its seems qobject_cast is isinstance, and much of the code should be the same
except here it takes all widgets from the items in the layout.