I have a table widget with cells containing strings.I want to select a cell and then pushing a button to get the contents of the cell.
I thought to use tableWidget.currentItem(), but I get a QTableWidgetItem object.
For the button and the table I use QtDesigner.Any tips?Thanks.
Look at the documentation. It's really useful:
tableWidget.currentItem().text()
Related
I am trying to adjust the text on a per column basis in a docx table. I have tried
for row in doc.tables[2].column_cells(4):
font = run.font
font.size = Pt(8)
I don't get an error with the above code, but I also am not seeing any changes to the cell texts in that column
Make sure you are accessing the correct table: The code you provided is accessing the third table in the document (index 2) and the fourth column (index 3) of that table. Make sure that this is the table you want to make changes to, and that you are referencing the correct column.
Check the scope of the loop: Ensure that the loop is looping through the cells of the column correctly.
Use the .text attribute: the font attribute only affects the font of the text, not the text itself. You can use the .text attribute to change the text.
Apply the changes to the runs within the cells: Instead of changing the font of the whole cell, you should change the font of the runs within the cell. Each cell has a .paragraphs attribute that contains a list of the paragraphs in that cell, and each paragraph has a .runs attribute that contains a list of the runs of text within that paragraph.
for row in doc.tables[2].column_cells(3):
for paragraph in row.paragraphs:
for run in paragraph.runs:
run.font.size = Pt(8)
Save the changes: Remember to save the changes to the docx file after you have made the changes.
doc.save("updated_table.docx")
I have a list that looks like this in my UI:
UI image
The XPATH for the first row's "..." button is //tbody/tr[1]/td[2]/a[1]/i[1], and each subsequent row's XPATH has the tr[] portion updated depending on the index of the row.
Is it possible to store the xpath of the button as:
button = //tbody/tr[i]/td[2]/a[1]/i[1] ?
And if so, if I create a new rule, is there a way I can update tr[i] to reflect the index of the newly added rule so I can call button.click()?
looks like, you wanna make indexing bit dynamic :
so, for this xpath :-
//tbody/tr[1]/td[2]/a[1]/i[1]
you can do following:
i = 1
button = f"//tbody/tr[{i}]/td[2]/a[1]/i[1]"
and can use it in Selenium.
you can use it for loop as well with the indices.
I want to put my picture and table(only 1 cell) like below:
Click here to see picture
I have to use such table because python-docx can't handle text-box yet. Basically I need to put my table beside my picture, not below or upper. I find that paragraph.run has add_picture() method to add picture at the end of paragraph, but not add_table() method to add one more table. Anyone know how to achieve this
i have tried so many ways to put a picture into a table ,that is what i do deal with my problem, you may find something you can use
from docx import Document
document = Document
table = document.add_table(rows=2, cols=3)
# set the whole table in the center position
table.alignment = WD_TABLE_ALIGNMENT.CENTER
row_cell = table.add_row().cells
# choice one row
**row_pic = row_cell[0]**
# clear blank area
**row_pic._tc.clear_content()**
# use paragraph function
**pic_run = row_pic.add_paragraph().add_run()**
# insert a picture path as a str into a cell from a table
**pic_run.add_picture('./picture/{}'.format("picture_name.jpg"), width=Inches(5))**
I'm using gtk treeview in one of my applications.
Application works as follows:
I extract some data from logfile and add the important data to my splite database and then, I show the data in treeview by fetching the rows from the database.
Now my question is how can I add newline character, so that I can add multi-lines in the treeview cellrenderer.
I tried this by setting the cellrenderer "markup" property and then tried adding "\n" and then with the tag. In case of "\n" it prints the "\n" as it is in the treeview cell. And gives following error if I try to add tag.
GtkWarning: Failed to set text from markup due to error parsing markup: Unknown tag 'br' on line 1 char 18
gtk.main()
So how can I add multilines to a gtk treeview cell?
Thanks in advance
With regards to automatically flowing text, CellRendererText should just do the right thing if you set wrap-width property to a value that isn't -1.
If automatic wrapping is not enough and you really need separate paragraphs, I think you may need to implement your own CellRenderer (which is not trivial) or use another container like a ListBox (where custom widgets are easy, but which will mean throwing away your treeview code...).
I have a tab widget with tablewidgets in each one, containing cells with links.I know how to get the current text from a tablewidget and open it in a browser,which is what i want to do.
selection=str(self.tableWidget_1.currentItem().text()).encode('utf8')
webbrowser.open(selection,new=2)
My problem is that I don't know how to get the current tablewidget instead of predetermined like above.Any ideas?Thanks.
See QTabWidget.currentWidget.