Monday, May 1, 2017

How to fill QTextEdit of another class

1 comment

I have two classes.

The class mask_n_functions controls a form that fills up a SQLite database. There is the method call_inventory_mask which opens a new mask class inventory_function(QDialog, Ui_Inventory):. There I can check some CheckBoxes and fill up a list (InventoryList) with some elements.

Now I want to fill up a QTextEdit of a form which is called with the class mask_n_functions with resulting InventoryListString.

I want to use this for a QGIS Plugin. I use Notepad++ for coding.

I tried self.mask_n_functions.inventory_list.setText(InventoryListString),

UPDATE: There is no python error occurring within QGIS. The QTextEdit field of the mask, called with the class mask_n_functions, still remains empty.

Here is my (reduced) code:

class inventory_function(QDialog, Ui_Inventory):      def __init__(self, parent):         QDialog.__init__(self, parent)         self.setupUi(self)          self.get_inv.clicked.connect(self.getInventory)         self.close_inv.clicked.connect(self.closeInventory)      def getInventory(self):         getInventoryList = [['inv1','Example2'],['inv2','Example2'],['inv3','Example3']]         InventoryList = []         for l in getInventoryList:             checkboxstring = str(l[0])             checkboxname = checkboxstring.strip()             checkbox = getattr(self, checkboxname)             if checkbox.isChecked():                 InventoryList.append(l[1])         InventoryListString = '%s' % ', '.join(map(str, InventoryList))         self.mask_n_functions.inventory_list.setText(InventoryListString) # inventory_list is a QTextEdit() widget of Ui_MainForm in the class mask_n_functions         self.close()      def closeInventory(self):         self.close()  class mask_n_functions(QDialog, Ui_MainForm):      def __init__(self, parent):         QDialog.__init__(self, parent)         self.setupUi(self)          global now         now = datetime.datetime.now()          global username         username = getpass.getuser()          ...          self.choose_inventory.clicked.connect(self.call_inventory_mask)      def call_inventory_mask(self):         inventory_mask = inventory_function(self)         inventory_mask.show() 

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

1 comment:

  1. Ashleys furniture
    Occasionally it may be a sensible idea to select reputable brands to design your house. You will radiate confidence with the environment you encounter.However, it is not just for this purpose that you really want the greatest brands to purchase. Each is distinctive and provides your house a different type of décor. The choices you choose rely on your own particular requirements and needs.

    ReplyDelete