Sort by QLineEdit in QTableWidget - qt

I have a QTableWidget that has a combination of QLineEdit and normal table cell items. I would like to know the best way to sort the data in the table by the values in the QLineEdit column.
Here is an example.
| customer code | header | message |
------------------------------------------------
| QLineEdit | normal cell | normal cell |
| QLineEdit | normal cell | normal cell |
| QLineEdit | normal cell | normal cell |
| QLineEdit | normal cell | normal cell |
| QLineEdit | normal cell | normal cell |
I would like to sort on the customer code column but because it's a QLineEdit (set with setCellWidget()), the table won't sort by its values.
I know I could take each value out, place them in a temporary object or row and shuffle the rows around but that would be amazingly ugly and slow. Is there a better way to do this?

There are several ways to approach this, here are a couple of ideas:
Use QTableWidgetItem::setText() on your cells that have the line edits in them. If you keep the text that's set on the cell sync'd with what's in your line edits then the sorting behavior should be preserved.
Subclass QTableWidgetItem and overload the < operator, at which point you can grab the line edits out and compare their values manually.

Related

Display code in two columns in restructured text

Using restructured text, how can I display two code blocks side by side, so that they can be compared line by line?
Here is an example of what I mean from this similar question for Markdown: How to disply two markdown code blocks side by side
Ok, so I found that the following works:
+-------------------------+-------------------------+
| | |
|.. code-block:: |.. code-block:: |
| | |
| # Code example 1 | # Code example 2 |
| | |
+-------------------------+-------------------------+
This creates a table with two columns, and puts a code block in each of them. If the two blocks have the same number of lines, they will be aligned to each other. The output looks like this:
If one wants to include an external script, it can be done like this:
+--------------------------------+--------------------------------+
| | |
|.. literalinclude:: script_1.py |.. literalinclude:: script_2.py |
| | |
+--------------------------------+--------------------------------+

QGraphicsItem under cursor at leaving object while over another item

I have a QGraphicsScene, QGraphicsView and some QGraphicsItems subclassed.
I want to track which item is under the cursor topmost visible.
It works fine using hoverEnterEvent in most situations, but if I have two Objects where one is on top of another it does work on entering both but not on leaving the inner object (and re-entering the outer, since it never left the outer in the first place).
+-------------------------------------+
outside | |
| outer |
| |
| |
| +-------------+ | +-------------+
| | | | | |
| | | | | another |
| | inner | | | |
| | | | | |
| | | | +-------------+
| +-------------+ |
| |
| |
| |
| |
+-------------------------------------+
outside -> outer : works, outer is selected
outside -> outer -> outside -> another : works, first outside is selected, than nothing, than another
outer -> inner : works, inner is seletected
outside -> outer -> inner -> outer: does not work, first outside is selected, than inner, but than nothing (should be outer again)
What can I do, besides looping trough all graphicitems triggered via a slight delayed singleshot on hoverLeaveEvent?
Edit:
I found a temporary solution:
I added a global QList < MyQGraphicsItem *> where on MyQGraphicsItem::hoverEnterEvent I add "this", and on MyGraphicsItem::hoverLeaveEvent I remove the last item in the List. So the myGlobalQList.last() always contains the topmost item visible under the cursor.
I assume this is not the best solution since QList is not threadsafe, therefor I am still interested in other solutions.
Your QGraphicsItems live in a QGraphicsScene which can be displayed by one or more QGraphicsViews.
I know that the model-view mapping usually is 1:1.
Still I suggest to implement mouse handling like this in your view, not in the scene:
Install an eventFilter on your graphicsView->viewport().
Override the eventFilter() function in your filter class.
Watch for QEvent::MousePress, MouseMove, MouseRelease, maybe Enter and Leave, depending on what you need.
Probably you need to setMouseTracking(true) on the viewport.
Then, in the event filter function, use QGraphicsView::mapToScene() and QGraphicsScene::itemAt() to find the topmost item, or ::items() to find all items under the cursor.
I recently used this to decorate the topmost item with a border by painting over the view (QGraphicsView::drawForeground()).

Spark Datagrid with Splitted columns

I'm trying to figure out how can i get that a simple Datagrid has splitted columns.
I need the following layout:
+-------------------+
| Destination |
+--------+----------+
| Dir 1 | Dir 2 |
+-------------------+
Any idea about how could I do it?
You can use a header renderer for the same. Customized renderers can be created.

How can I set the value of a dictionary element to the result of a keyword in Robot Framework?

I know that I can access a single element from a dictionary object with this format ${dict['KEY']}. Like this:
| | Log | ${dict['KEY']} |
And I can set a regular old scalar like this:
| | ${scalar}= | RFKeyword | "Yowp"
But if I try to set a dictionary element like this
| | ${dict['KEY']}= | RFKeyword | "Yowp"
I get "RFKeyword", "Yowp" in the variable, rather than the result of what RFKeyword produces when processing "Yowp" like I do with this
| | ${scalar}= | RFKeyword | "Yowp"
Assistance please
As you probably have figured out, you can't assign to a dictionary from a keyword. You need to very specifically follow the dictionary syntax. you can only return variables to lists or scalars.
Robot framework isn't a fully fledged programming language, and it shouldn't be. By using an intermediate scalar, non-technical testers should be better able to understand what it is doing.
I added this since a google search for "robot framework dictionary" has this question high up in the list.
Just create dictionaries with:
Create dictionary | ${my_dict} | a | b
Add to dictionaries with:
set to dictionary | ${my_dict} | c | d
And retrieve from dictionaries with:
${my_dict["a"]}
Or, if you need to not fail:
${my_dict.get('non-key','default value')}
You just need to rearrange the way you call it. So for your keyword where you want the returned data to go into your dictionary you need to do the following:
${scalar}= | RFKeyword | "Yowp"
Set To Dictionary | ${dict} | KEY | ${scalar}

Vertical spacing between display:inline divs in a fluid grid

Ok, not too sure where to start...
I'm putting myself together a blogger, completely gutting it's css and just using it as a simple content manager. here is the test site i've been working with
http://jamesparishtestblog.blogspot.com/
Ignore the header, its broken, but I know what I'm doing there. My problem is with the film reviews (stolen from apple trailers as temp content). As you resize the page, they flow fluidly into rows of different lengths. Great! Trouble is, the second row (and thus third, fourth, etc.) aligns itself vertically to the bottom of the longest (lowest) div in the above row. However, I want each div to fit neatly below the one above, 15px apart, and to flow neatly if another div is expanded (by clicking read more...).
Placing the divs in a column is ruled out, because I want the top row to contain the most recent posts side by side (with a column they would be below one another on the left hand side).
Set heights for the divs is ruled out too, because the articles need to expand, and for the full desired design, be mis-matched intentionally.
This has been troubling me for hours. I hope I've explained myself clearly, and that someone will can help.
Thanks for your time.
So you want this?
--------------------------
| __________ _______ |
| | | | | |
| | | | | |
| | | | | |
| ---------- | | |
| __________ | | |
| | | |_____| |
| | | _______ |
| | | | | |
| ---------- | | |
| ------- |
|________________________|
Without using columns you can't do it relying on CSS alone. You'd need to use some javascript or server side stuff to put things in the right place. Essentially you want a collage, too bad there's no "display: collage"!
Of course, I could be completely misunderstanding you.
Edit:
"any suggestions on the javascript front?"
I use mootools for almost all my sites. I'll define a bit there first:
dispose : takes an element out of the dom and stores it in a variable.
inject : plops an element into the dom.
I'd load these into columns, then dispose all the ones in the "recent" column and inject them back in to the top of the rest of the columns, one for each column. In other words, all the layout is done with CSS, the only javascript going on is putting your "recent" stuff as the top "row".

Resources