Appending Qtablewidget row contents to qLineEdits
-
okay.
Then to make the selected row contents of the qTableWidget appear on their corresponding lineEdits, do you mean I should use this instead:for row in rows: texts = [] **for j in range(self.itemList.columnCount())**: itemcodd = self.tab.item(row, 0) text = "" if itemcodd is None else itemcodd.text() texts.append(text) line = " ".join(texts) lines.append(line) output = "\n".join(lines) **self.itemList[0].setText(output)**
?
-
okay.
Then to make the selected row contents of the qTableWidget appear on their corresponding lineEdits, do you mean I should use this instead:for row in rows: texts = [] **for j in range(self.itemList.columnCount())**: itemcodd = self.tab.item(row, 0) text = "" if itemcodd is None else itemcodd.text() texts.append(text) line = " ".join(texts) lines.append(line) output = "\n".join(lines) **self.itemList[0].setText(output)**
?
@CEO
if you use that code as is, you will get all text for all cols into all LineEdits.
You are appending all texts and you don't need that
as the text you want should be in text variabletext = "" if itemcodd is None else itemcodd.text()
I assume the itemcodd.text() is the text you want into the right LineEdit, correct ?
-
Hi
As i shown higher up.rows = {index.row() for index in self.tab.selectionModel().selectedIndexes()} lines = [] itemList = [] itemList.append(self.itemcodetabtx) itemList.append(self.itemnametx) itemList.append(self.comtabtx) itemList.append(self.modifiertabtx) itemList.append(self.modeltabtx) itemList.append(self.partntabtx) itemList.append(self.sizetabtx) itemList.append(self.matltabtx) itemList.append(self.rattabtx) itemList.append(self.mfrtabtx) itemList.append(self.additx) itemList.append(self.usertabtx) for row in rows: texts = [] for j in range(self.tab.columnCount()): itemcodd = self.tab.item(row, 0) text = "" if itemcodd is None else itemcodd.text() self.itemList[j].setText(text) // set the text to line edit via the list.
@mrjj ohhhkay!!
I just studied this again and I got your point. I understand it now. It works fine now.It works fine now.
Do I have to be repeating the 'for loop' statement for the other columns?
Lest I forget, I am very grateful for you attention.for row in rows: #texts = [] for j in range(self.tab.columnCount()): itemcodd = self.tab.item(row, 0) text = "" if itemcodd is None else itemcodd.text() itemList[0].setText(text)
-
@mrjj ohhhkay!!
I just studied this again and I got your point. I understand it now. It works fine now.It works fine now.
Do I have to be repeating the 'for loop' statement for the other columns?
Lest I forget, I am very grateful for you attention.for row in rows: #texts = [] for j in range(self.tab.columnCount()): itemcodd = self.tab.item(row, 0) text = "" if itemcodd is None else itemcodd.text() itemList[0].setText(text)
Hi
Ok super. Was afraid I didn't explain good enough.Well in my book the
for j in range(self.itemList.columnCount()):
should loop all coloums for the selected Row.Do notice that code won't do right if you select multiple rows but I assume that was not the plan.
You are very welcome. Disclaimer. I suck at python as such but programming is programming and
same tactics works regardless of language used-Whoops
Just saw
itemList[0].setText(text)
should be
itemList[j].setText(text)so we take next index when we take next col.
I assume j will go 0,1,2,3,4 etc ?
also when you take the text
itemcodd = self.tab.item(row, 0)
should that not be itemcodd = self.tab.item(row, j)
so we take cols one by one and not just 0 (zero) -
@CEO
What we try is to have a list of the edits so ew don't have to use names. else you have to do
som ifs to make them go into the right line edits.for j in range(self.tab.columnCount()): itemcodd = self.tab.item(row, j) text = "" if itemcodd is None else itemcodd.text() if (j ==0 ) self.itemcodetabtx.setText(text) if (j ==1 ) self.itemcodeSOMEOTHERNAME.setText(text) ....
- Is there any difference between self.itemcodetabx.setText(output) and self.itemList[0].setText(output)?
No. not really as in both cases we use a pointer to talk to the Lieedit but with LIST we
can do it via index (j) and not name so its easier as else you must use if statements to star it in to the right edit . the one that matches the current column.@mrjj said in Appending Qtablewidget row contents to qLineEdits:
@CEO
What we try is to have a list of the edits so ew don't have to use names. else you have to do
som ifs to make them go into the right line edits.for j in range(self.tab.columnCount()): itemcodd = self.tab.item(row, j) text = "" if itemcodd is None else itemcodd.text() if (j ==0 ) self.itemcodetabtx.setText(text) if (j ==1 ) self.itemcodeSOMEOTHERNAME.setText(text) ....
- Is there any difference between self.itemcodetabx.setText(output) and self.itemList[0].setText(output)?
No. not really as in both cases we use a pointer to talk to the Lieedit but with LIST we
can do it via index (j) and not name so its easier as else you must use if statements to star it in to the right edit . the one that matches the current column.This answers my most previous question. I like this format. Thanks a bunch.
-
@mrjj said in Appending Qtablewidget row contents to qLineEdits:
@CEO
What we try is to have a list of the edits so ew don't have to use names. else you have to do
som ifs to make them go into the right line edits.for j in range(self.tab.columnCount()): itemcodd = self.tab.item(row, j) text = "" if itemcodd is None else itemcodd.text() if (j ==0 ) self.itemcodetabtx.setText(text) if (j ==1 ) self.itemcodeSOMEOTHERNAME.setText(text) ....
- Is there any difference between self.itemcodetabx.setText(output) and self.itemList[0].setText(output)?
No. not really as in both cases we use a pointer to talk to the Lieedit but with LIST we
can do it via index (j) and not name so its easier as else you must use if statements to star it in to the right edit . the one that matches the current column.This answers my most previous question. I like this format. Thanks a bunch.
@CEO
Ok. using ifs are also fine. :) -
aim accomplished. ALL THANKS to you. Honestly if you had directed me to QT documentation, I wouldn't have been able to understand it. I appreciate.
@CEO
Np. Glad you could make it work.If you ever need to make something like this again, You can get most of it for free/no code
if you use a standalone model as then you can also connect the LineEdits to the model with the table and it would auto sync. -
aim accomplished. ALL THANKS to you. Honestly if you had directed me to QT documentation, I wouldn't have been able to understand it. I appreciate.
@CEO alright. I am grateful.
I have been thinking of ways I can design the table lines. is it possible please? For now, I can only setStylesheet to the table background. Is there anyway I can thicken the table lines and maybe give it another color different from the table background?
-
@CEO alright. I am grateful.
I have been thinking of ways I can design the table lines. is it possible please? For now, I can only setStylesheet to the table background. Is there anyway I can thicken the table lines and maybe give it another color different from the table background?
@CEO
Well there is
https://doc.qt.io/qt-5/qtableview.html#gridStyle-prop
that allows you to set pen and color when drawing the grid.Its also avialable for TableWidget as it inherits qtableview
-
@CEO
Well there is
https://doc.qt.io/qt-5/qtableview.html#gridStyle-prop
that allows you to set pen and color when drawing the grid.Its also avialable for TableWidget as it inherits qtableview
-
@CEO
Well there is
https://doc.qt.io/qt-5/qtableview.html#gridStyle-prop
that allows you to set pen and color when drawing the grid.Its also avialable for TableWidget as it inherits qtableview
@mrjj I have studied the content. Honestly I hate reading QT documentations because they don't teach an individual how to use them. No illustrative example. Most things I know today, I learned from other links.
I have practicalized self.tab.setGrid() I don't know options to use. No much work on QT online and learning through the documentation is terrible. -
@CEO
Well there is
https://doc.qt.io/qt-5/qtableview.html#gridStyle-prop
that allows you to set pen and color when drawing the grid.Its also avialable for TableWidget as it inherits qtableview
@mrjj I found a better site to learn more about Qtablewidget. >>>>> https://topic.alibabacloud.com/a/use-of-qlistwidget-and-qtablewidget-and-style-settings_8_8_10259690.html
I hate Qt documentation site. They make it difficult for a beginner to understand
-
Hi
Ok super. Was afraid I didn't explain good enough.Well in my book the
for j in range(self.itemList.columnCount()):
should loop all coloums for the selected Row.Do notice that code won't do right if you select multiple rows but I assume that was not the plan.
You are very welcome. Disclaimer. I suck at python as such but programming is programming and
same tactics works regardless of language used-Whoops
Just saw
itemList[0].setText(text)
should be
itemList[j].setText(text)so we take next index when we take next col.
I assume j will go 0,1,2,3,4 etc ?
also when you take the text
itemcodd = self.tab.item(row, 0)
should that not be itemcodd = self.tab.item(row, j)
so we take cols one by one and not just 0 (zero)@mrjj hello Mr. JJ, I am having challenge retrieving data into a qTablewidget. I have been retrieving data into qtablewidget before.
I used qtable in storing the data into the database and one of the columns in the table used qcombobox. Is it that I will have to retrieve that data into a qcombobox too?
I am asking this because I'm not seeing any error in my retrieval code.