Finding a QWidget's height before inserting - qt

I have a widget to insert that looks like this
+--------------------+
| +-------++-------+ |
| | || | |
| | || | |
| | || Label | |
| | Label || Label | |
| | || | |
| | || | |
| +-------++-------+ |
+--------------------+
A QWidget element containing two QVBoxLayouts, each containing one or more QLabels.This Widget is going to be inserted in a Vertical Layout that has a stretch cell, so all the widgets of this kind will go to the top and shrink to the smaller height possible.
Resulting in something like this.
______________________ ← Layout boundary
+--------------------+
| +-------++-------+ |
| | || Label | |
| | Label || Label | | ← Widget shrunk to the smallest
| +-------++-------+ |
+--------------------+
______________________ ← Layout boundary
↑
|
| ← Spacer
|
↓
______________________ ← Layout boundary
But before doing this insert, I want to know the size that the widget would have in the inserted layout. Maybe the minimum size allowed by its internal layout. Not sure how to call it.
I have tried already many approaches like inserting the widget in an alternate invisible layout so I can retrieve its height when inserted, which should be the same that the widget would take when inserted in my definitive layout.
But for some reason I always get 480 or 478 when the widget is at most 50px height when pressed vertically. So I am totally lost.
I have to do this because I need the widget to animate when inserting, and I need to know the height it will take for me to animate from height 1 to it.
How can I do this?

Without having the exact code, it's hard to say for sure, but having just attempted to reproduce your example, from the description above, I'd suggest looking at the following things:
It sounds like you're actually calling widget->height() before the widget has been displayed. Instead, try calling widget->sizeHint().height() instead. The QWidget::sizeHint() method tells you what size the widget would like to be, if the parent geometry doesn't place any other constraints on it.
If you're obtaining the sizeHint() and still getting the wrong answer, have a look at the documentation for QWidget::ensurePolished(). I believe that it's important to call this, to get more accurate geometries for widgets that have not yet been displayed:
QWidget calls this function after it has been fully constructed but before it is shown the very first time. You can call this function if you want to ensure that the widget is polished before doing an operation, e.g., the correct font size might be needed in the widget's sizeHint() reimplementation.
And if you're still having problems, then have a look at the documentation for QWidget::sizePolicy(), and the class QSizePolicy Class Reference. I must admit that however many times I read the docs on enum QSizePolicy::Policy, they never all sink in. It's really easy to have one incorrect size policy value mess up your layouts.
It can be worth experimenting with the different size policies in Qt Designer, before actually applying a size policy.

Related

Fitnesse Ignore result of method

I am trying to run this fixture code:
|script |Browser Test |
|open |https://jsfiddle.net/ygjL7hnm/3/show|
|click |Run this fiddle |
|click if available|id=test |
|click if available|id=test2 |
|click if available|id=test3 |
|click if available|id=test4 |
|wait |2 |seconds |
The problem is I want to ignore the result of "click if available", meaning the test should be all green. I could do that with "reject". That would work perfectly fine but the problem is I don't know which buttons are missing or not missing. So I would have to write "reject" before every "click if available". That results in an error if the button is actually available. As you can see here:
But what I want is that no matter if the button is there or not, it should just try to click it and ignore the result of the method. It should not check wether it found the button or not. I hope its clear what I want, if not feel free to ask. Thanks.
Edit: Worth noting I am using this fitnesse version with the HSAC PlugIn.
For slim tests (which in this case, you are using), prepend the script table row with the show keyword. It will just output the function's return value. (true/false in case of 'click if available')
More info: http://fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.ScriptTable
From that link:
If the word show is in the first cell, then it should be followed by a function. A new cell will be added when the test is run, and it will contain the return value of the function.
The script below should not fail on the execution of click if available:
|script |Browser Test |
|open |https://jsfiddle.net/ygjL7hnm/3/show |
|click |Run this fiddle |
|show |click if available |this does not exist |

AwesomeWM tag with static layout

StackOverflow is denoted as a place for AwesomeWM community support.
I would like to have a dedicated Tag in my AwesomeWM config where only three particular application will be running all the time. I managed to create new tag using sample config, and I managed to filer the applications using awful.rules.rules and place them into the tag.
I am experiencing troubles in understanding how AwesomeWM layout engine really works. I would like to achieve the following: three static columns of fixed widths, each application is located at its own column, when focus changes then no rearrangement happens, when any application is not running, then its reserved place is remain empty.
___________________
| | | |
| | | |
| A | B | C |
| | | |
| | | |
___________________
How do I specify layout in such case? Should I write my own one? Can I use flexible layout and specify position for client? What is the recommended correct way to achieve my goal?
I am experiencing troubles in understanding how AwesomeWM layout engine really works
A layout is a table with two entries:
name is a string containing, well, the name of the layout
arrange is a function that is called to arrange the visible clients
So you really only need to write an arrange function that arranges clients in the way you want. The argument to this function is the result of awful.layout.parameters, but you really need to care about
.clients is a list of clients that should be arranged.
.workarea is the available space for the clients.
.geometries is where your layout writes back the assigned geometries of clients
I would recommend to read some of the existing layouts to see how they work. For example, the max layout is as simple as:
function(p)
for _, c in pairs(p.clients) do
p.geometries[c] = {
x = p.workarea.x,
y = p.workarea.y,
width = p.workarea.width,
height = p.workarea.height
}
end
end
Should I write my own one? Can I use flexible layout and specify position for client?
Well, the above is the write-own-layout approach. Alternatively, you could also make your clients floating and assign them a geometry via awful.rules. Just have properties = { floating = true, geometry = { x = 42, y = 42, width = 42, height = 42 } }. However, with this you could e.g. accidentally move one of your clients.
What is the recommended correct way to achieve my goal?
Pick one. there is no "just one correct answer".

What's the best way to have a grid of QWidget with fixed size column?

I am trying to build this QWidget with Qt :
| QLabel 00 | QLabel 01 | QPushButton |
| QLabel 10 | QLabel 11 | (Nothing here) |
| QLabel 20 | QLabel 21 | (Nothing here) |
Currently I have done it with a QGridLayout, the thing is I want the first and last column with a fixed width and QGridLayout doesn't have this feature. Indeed the first and last columns expand depending on QLabels 01, 11 and 21 size.
Is there a best way to have a fixed witdh on a specific column or did I miss something on the QGridLayout?
Try QGridLayout::setColumnStretch...
my_grid_layout.setColumnStretch(0, 0);
my_grid_layout.setColumnStretch(1, 1);
my_grid_layout.setColumnStretch(2, 0);
The above should cause the grid layout to associate all extra width with column 1.

Use oene physical monitor as two

I have a Big monitor which I would like to simulate more than one monitor.
i.e:
------------
| |
| M1 |
------------
should be treated as:
-------------
| M1 | M2 |
| | |
-------------
I'm running AwesomeWM version 3.5.9 on X11 1.18.3. I don't care if I can achieve this behaviour by changing the settings of my window manager or the xserver. Whichever way is the easiest.
Cheers
Edit: June 2019. A new feature currently under review for AwesomeWM v4.4 will add a :split() method to the screen API. It does what is done below, but better.
I just answered this question here:
Let awesome wm use only a part of the screen
This is the code:
local wdh = screen[1].geometry.width/2
local x, y = screen[1].geometry.x, screen[1].geometry.y
screen[1]:fake_resize(x, y, wdh, screen[1].geometry.height)
screen.fake_add(x+wdh+1, y, wdh, screen[1].geometry.height)
I will add this to the documentation soon.

React native firebase 'average' query?

I come from a php/mysql background, and json data and firebase queries are still pretty new to me. Now I am working in React Native and I have a collection of data, and one of the keys stores a integer. I want to get the average of all the integers. Where do I even start?
I have used Firebases snapshot.numChildren function before so I am getting a little more familiar in this json world, but any sort of help would be appreciated. Thanks!
So, you know that you can return all of the data and determine the average. I'm guessing this is for a large set of data where it would be ideal not to return the entire node every time you would like to retrieve and average.
It depends on what this data is and how it's being updated, but I think one option is to simply have a separate node that is updated every time the collection is added to or is changed.
Here is some really rough pseudo code. For example, if your database looks like this:
database
|
+--collection
| |
| +--item_one (probably a uid like -k2jduwi5j5j5)
| | |
| | +--number: 90
| |
| +--item_two
| | |
| | +--number: 70
|
+--collection_metadata
| |
| +--average: 80
| |
| +--number_of_items: 2
Then when a new item is added, you run a metadata calculation:
var numerator = average * number_of_items + newItem.number;
number_of_items++; <-- this is your new number of items
numerator / number_of_items; <-- this is your new average
Then when an item is updated, you run a metadata calculation:
var numerator = average * number_of_items - changedItem.oldNumber + changedItem.newNumber;
numerator / number_of_items; <-- this is your new average
Now when you want this data, you always have this data on hand.

Resources