PyQt:How do I get the current tablewidget in a tabs widget? - python

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.

Related

How to access the start and end index of a selected text from kivy textinput

That's my doubt. How to access the first and last index of the selected text in kivy-TextInput. And also if possible can u tell me how to get the selected text.... I tried TextInput.selection_text but it just gives ''. Nothing else.. Hope that no code or example is needed

Add New line in pygtk Treeview

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

Python Tkinter Text Area set cursor to end

I have a Tkinter Text() object and I append lines to it using .insert(END, string). When the text fills the available area, I'd expect it to scroll down to show the bottom line of text in the view, but it doesn't scroll (meaning the user has to scroll themselves to see the latest text). I've had a look at the mark_set() method but I can't seem to figure out how to get the cursor to the index of the last item of text.
Any help would be appreciated :)
As usual with Tkinter, there are a number of ways to do this, but one is the easiest: Text.see:
text.insert(END, "spam\n")
text.see(END)
If you want to make sure the start of the new text is visible, not the end of it, or if you only want to do this if the end was already visible beforehand or if the text is active, etc., you may need to look at the other options: scan_mark/scan_dragto, or yview and friends.

PyQt:How to get contents of selected cell in table widget?

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()

Text in Text Widget as a variable

so I've got this little Text widget with a scroll bar and I've got a question. How do I make text in this Text widget a variable ? If I made this text a variable I would be able to open a text file and edit it's text or save the text I've written, etc or maybe it's a wrong way that I'm approaching this, is there a better way to do this ?
There is no option to associate a variable with a text widget. You can achieve the same thing by using variable traces and widget bindings but it's rarely worth the effort.
The typical way to interact with the text widget is to read a file into a variable then use the insert method of the widget to put the text into the widget. Then, to save you just do the reverse -- get the text from the widget with the get method, and write the data to a file.
One tip: when you do a get, don't get the text from 1.0 to "end", use "end-1c" instead. If you specify "end" as the last character you'll get the implicit newline that tk always adds, meaning your text file will grow by one character each time you do a load/save cycle.

Categories