Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there a Widget for PyQt5 for Phyton that remove all from layout ?
Forum Updated to NodeBB v4.3 + New Features

Is there a Widget for PyQt5 for Phyton that remove all from layout ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 5.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS SGaist

    Can you explain a bit more what you UI is about ?

    S Offline
    S Offline
    Sergei_Rack
    wrote on last edited by
    #5

    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.1_1523369381698_before.png 0_1523369381696_after.png

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #6

      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.

      S 1 Reply Last reply
      0
      • mrjjM mrjj

        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.

        S Offline
        S Offline
        Sergei_Rack
        wrote on last edited by
        #7

        @mrjj Yes, you got it.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #8

          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.

          S 1 Reply Last reply
          0
          • mrjjM mrjj

            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.

            S Offline
            S Offline
            Sergei_Rack
            wrote on last edited by
            #9

            @mrjj Thanks for your answer. Will be nice to have a Widget to do so. Maybe we can ask for it to QT.

            mrjjM S 2 Replies Last reply
            0
            • S Sergei_Rack

              @mrjj Thanks for your answer. Will be nice to have a Widget to do so. Maybe we can ask for it to QT.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #10

              @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.

              S 1 Reply Last reply
              0
              • S Sergei_Rack

                @mrjj Thanks for your answer. Will be nice to have a Widget to do so. Maybe we can ask for it to QT.

                S Offline
                S Offline
                Sergei_Rack
                wrote on last edited by
                #11

                @Sergei_Rack Could you do an example for me, please.

                mrjjM 1 Reply Last reply
                0
                • S Sergei_Rack

                  @Sergei_Rack Could you do an example for me, please.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  Hi
                  Yes later this evening i can.

                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @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.

                    S Offline
                    S Offline
                    Sergei_Rack
                    wrote on last edited by
                    #13

                    @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.

                    mrjjM 1 Reply Last reply
                    0
                    • S Sergei_Rack

                      @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.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      @Sergei_Rack
                      oh, i forgot its python
                      Will a c++ sample works ?
                      I dont use pyt at all.

                      S 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @Sergei_Rack
                        oh, i forgot its python
                        Will a c++ sample works ?
                        I dont use pyt at all.

                        S Offline
                        S Offline
                        Sergei_Rack
                        wrote on last edited by
                        #15

                        @mrjj Well yes, I try to convert from C++ to Phyton.

                        mrjjM 1 Reply Last reply
                        0
                        • S Sergei_Rack

                          @mrjj Well yes, I try to convert from C++ to Phyton.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #16

                          @Sergei_Rack
                          Hi, ok
                          I was thinking something like

                          void 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.

                          alt text

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved