How to add toolTip for objects in QTextBrowser? - python

I'm adding some paragraphs in QTextBrowser and want to add toolTip for them. I tried using hover but QTextBrower doesn't support hover I think.
I'm able to call a function on clicking though.
EDIT:seperate toolTip for each one.

I don't know how you're adding the paragraphs, but if you're using markup the solution is simple: just use the title attribute.
<p title="tootip">some block of text</p>
However, if the paragraphs are being added programmatically, you can use QTextCharFormat, which has a setToolTip method.

Did you try this?
b=QTextBrowser()
b.setToolTip('Simple text browser')
It works for TextFields

Related

how to locate button using selenium python

I have tried many ways and seen many posts on Stackoverflow but i cannot find a solution.
I need to access this button and click it, any ideas?
<a class="button secondary radius" href="/logout"><i class="icon-2x icon-signout"> Logout</i></a>
If there are other buttons with the same class names you can try this way
driver.find_element_by_xpath('//input[#href="/logout"]').click();
this button has three classes button secondary and radius. Just use driver.find_elements_by_class_name("name of the class"). Insert one of the classes from above but be carefull, the class can only be used onces on the entire page or you might run into issues.

Python Selenium--Locate a Div ID

I have to click on an image of a dropdown arrow in order to select an item that will populate the input box.Both of them are refered into the dev id:decision. I need your help in order to make my python code to click the image of the arrow and to select a decision. YOu can see in the images what the event of clicking the arrow make.
At least i was looking for a solution to input the text in the input box, but i can't locate properly the input box. I tried with class or xpath and still i can't locate it.
The input class of the input box is pdl_control, but when i used that i got the text populated into another input box in the form.
----Later Edit. The input is not working properly. I have to select the elements from the dropdown list :( If you can help me, I would owe you a lot.
Thank you in advance!!!
1
2
Giving the answer to this question is not that straightforward.
You have only provided the HTML where there are two input boxes and one anchor tag which has an image as the hyperlink.
The href provides the link destination. In your HTML it is set to "#", that means on clicking the image, the event will be occurring on the same page.
The anchor tag has the on click event handler:
"return MultiSelectPDL_TogglePDL(event)"
The information which you have provided is not sufficient. You have to provide the complete HTML so that I can help you with this question.

Django - turn field into tags with dropdown

In my form on django, I have a field called package_includes and a field called price. Right now, the content in package_includes it is simply text. So if I input "paper, glue, glitter" it will display exactly as i typed it, unable to change anything. However, I want the text to work like individual tags ->How I want tags to look
So when you click on one of the individual items (EX: "paper", "glue", or "glitter") i want it to display a drop down that allows you the option to put extra glitter for an additional $2.00 to the total.
Also, at the end of the text I want a tag that displays "Add" and this function would allow you to add items not included in this specific package. For example, you should be able to add crayons for $5, highlighter for $2.50, etc.
I am new to programming and don't fully understand how to add a function to text like this in a field in django. Thank you in advance for your help!
The answer to your question is unfortunately not a step-by-step instruction of how to go from 0 to a complete working example - only a pointer in the right direction.
What you need is achieved through CSS (producing the visual effect you want) and JavaScript (handling the drop-down functionality; it most probably has to be your own script based on jQuery). All of what you want needs to live (execute) within the Internet browser, and Django can only help there by serving the static CSS and script files, and referencing them in the actual page, when you put them in the correct template.
Here is an example of Wagtail Admin doing something similar:
If you open the page source in your browser, all you will see as HTML code for this is the following:
<div class="field-content">
<div class="input ">
<input id="id_tags" name="tags" type="text" value=""hello world", blog" /><script>initTagField("id_tags", "/admin/tag-autocomplete/");</script>
<span></span>
</div>
</div>
But if you open the page with FireBug, your browser's Development Tools, or the Web Developer extension, with visual styles applied it will decompose to something like this:
If you notice, the applied style to the form input element is display: none;. What you see is actually the styled unordered list elements right after. In order to be able to use them in your script, you need to be able to get to them/their contents from within your JS function. One strategy would be to assign an id attribute to all of the visible <li> elements. It can be something counter-based (e.g. id="shopping-cart-item-0", id="shopping-cart-item-1", etc.). Another way would be to assign an id to the <div class="input"> element, and within your function get all its DOM descendants of type <li>. Whatever works better for you. Then you could parse the label (inner text) of the list element in your script to get the type of item you are dealing with, and from then on find the discount price and apply it...
I would suggest that you start with a working example - find some app that uses taggit or similar package for Django and install it in a test application. Then you can use your browser's or preferred web development extension to play around with the CSS on them and see how different options affect the visual aspect of what you need. Once you are comfortable with that, see how you can build drop-down menus with jQuery. I believe the jQuery site has enough tutorials on the topic.

Does web.py support search box? Like the search bar on the top right of stack overflow?

I'm new to web.py and front end.
The problem is that I didn't find any search box support in web.py cookbook. I did some research and it seems that web.py form only supports Textbox, Password, Textarea, Dropdown, Radio, Checkbox, Button.
I wonder if I can use form to add a search box like the right top of stackoverflow.
Any help would be appreciated.
Sorry that I didn't make it clear. What I was wondering is that to define a form inside python script and render it in .html, so that the search box layout would be generated like this:
.
For example, we can define a form like the following:
<pre>
<code>
register_form = form.Form(
form.Textbox("username", description="Username"),
form.Textbox("email", vemail, description="E-Mail"),
form.Password("password", vpass, description="Password"),
form.Password("password2", description="Repeat password"),
form.Button("submit", type="submit", description="Register"),
)
</code>
</pre>
but I didn't find any built in class for searchBox, something like web.form.SearchBox("..."), in which we can set the placeholder of the search box.
I solved the problem by defining the layout with html and bound the search box with a function, just like Henry's advice.
Again thanks for responses. Was confused at the beginning.

How do I select an element by its style from css (not inline) using webdriver (python)

I wish to use python-webdriver to select an element based on it's background highlighting colour. Normally, this bit of html:
<div class="line-highlight" style="background:#FD71B5;">
I would select it doing the following:
.line-highlight[style*='background:#FD71B5']
However, in this case I have different inline styling:
<div class="line-highlight" style=top:130px;height:28px;left:506px;width:434px;">
but the highlight colour (which is the same) is set in an external CSS, so the above selector does not seem to work.
Is there any way webdriver can select by style if that style is not inline?
Thanks,
Darren
Because the css you're looking for isn't part of the HTML markup you can't select element(s) as you would usually do.
Instead try to select by the class name ".line-highlight" then loop through the resulting element objects and for each element get the css background property value by using:
value_of_css_property("background")
(or any css property for that matter). Once an element matches the background you're looking for break from the loop and tada you found the element you are looking for.
Note if you're using Java use:
getCssValue(property-name)
What this link http://www.w3.org/2002/07/26-dom-article.html says about style.
Accessing the Style Associated With the Document
Each node in the document is associated with stylistic effects such as color, position, and
borders. These stylistic effects are not always part of the document and might be defined in
a separate section called a style sheet.
So as Selenium works with DOM only it can't locate elements as you want.

Categories