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. Beginner Question
Forum Updated to NodeBB v4.3 + New Features

Beginner Question

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 419 Views 1 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.
  • G Offline
    G Offline
    GaryN
    wrote on last edited by
    #1

    I know; this is NOT an uncommon title (and, probably, question).
    The questions I found either had dead links or did not answer my question (I also have bought the latest book for QT6, but this still hasn't helped. Gone through the online documentation as best as I can.

    That's all just in case you think I have come straight here, without spending some time searching. :)

    Okay, so I have built the beginnings of an interface using the designer mode (beautifully simple; just like old Visual Studio). However, I now want to read some data in from a file and assign it to defined text boxes/spinners.

    I have the basic code:

    # This Python file uses the following encoding: utf-8
    import os
    from pathlib import Path
    import sys
    
    from PySide2.QtWidgets import QApplication, QWidget
    from PySide2.QtCore import QFile
    from PySide2.QtUiTools import QUiLoader
    
    
    class Widget(QWidget):
        def __init__(self):
            super(Widget, self).__init__()
            self.load_ui()
    
        def load_ui(self):
            loader = QUiLoader()
            path = os.fspath(Path(__file__).resolve().parent / "form.ui")
            ui_file = QFile(path)
            ui_file.open(QFile.ReadOnly)
            loader.load(ui_file, self)
            ui_file.close()
    
    
    if __name__ == "__main__":
        app = QApplication([])
        widget = Widget()
        widget.show()
        sys.exit(app.exec_())
    

    And a file - modules.txt.
    I have a collection of spinners and textboxes, but let's assume a textbox called var1 and a spinner called var2.

    Where do I add the Python code to read in the text file and assign the values to the input box and spinner?

    I don't need the code to read in nor assign (I don't think; hahaha!) but where does this go within this code?

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      depends what you want to do with it. it its just to prime beginning values in Widget then do it under load_ui().

      I light my way forward with the fires of all the bridges I've burned behind me.

      1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by ChrisW67
        #3

        If this data load should happen when the widget is constructed then the last line of __init__ might a be good place to call a function that does the file access.
        If it should happen in response to a user, for example, clicking a button in the UI then this code should be called from a slot reacting to that event.

        G 1 Reply Last reply
        1
        • C ChrisW67

          If this data load should happen when the widget is constructed then the last line of __init__ might a be good place to call a function that does the file access.
          If it should happen in response to a user, for example, clicking a button in the UI then this code should be called from a slot reacting to that event.

          G Offline
          G Offline
          GaryN
          wrote on last edited by
          #4

          @ChrisW67
          Thank you.
          One of the issues when posting is to ensure you capture the full intent, and I clearly failed in that attempt.

          Yes, the intention is to have this occur on load. Though a future development might be to add the ability to use an explorer/finder window to locate the input file, that is not truly relevant or necessary at present.

          I did comprehend, as with VS, that I could attach the instructions to any object; so the user may carry out the update (this is the next step after this one, but a step I feel confident I can work out). My biggest issue, on opening the system up for the first time, was where I placed the initialisation of the controls (textboxes, spinners, etc) - and you have answered that.

          Again, thank you. :)

          1 Reply Last reply
          0

          • Login

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