I have recently come back to Qt (tried it for previous projects and opted against it) and am really liking everything about it thus far. I am writing a TV Guide style application that will display Episode Guide Data (EPG) for anywhere from 3-7 days, and this data will be fed in from a Database source.
Right now I am having a hard time determining if I should use a QGridLayout or a combination of QHBoxLayouts (for the episode data) with a single QVBoxLayout on the left side (for the channel name/icons). My main concern with QGridLayout is that I would break it up into “30 minute” blocks, but when programs started at say 3:45, I am not sure it would work correctly. To give a better idea of what I am going for with the GUI, this screenshot can be viewed…
http://www.itvt.com/files/u3/AT&T-u-verse-tv-epg-2009.jpg
Just on a side note, if I want to only display a segment of this (i.e. 3:00AM – 4:30AM) and say 10 channels, which option would it be easier to implement vertical/horizontal scrolling with? Would I need to stick them in a different widget for that behavior?
Use QGridLayout.
Explanations:
With QVBoxLayout and QHBoxLayout, the number of column per rows is not fixed (or the inverse if you use these layout the other way), for example you can have something like:
|----------------------|
|------|------|--------|
|----------|-----------|
If you add an item to a row, the row will relayout without interfering with others, so column are not aligned anymore. It can be really convenient for some GUI, but for what you want I think it's not practical.
Then you have QGridLayout, which is the way to go for your GUI: all columns are aligned. So you can divide the grid in columns of 15 min, and then span widgets on several columns. Example:
0 15 30 45 60 75 90
|----|----|----|----|----|----| 6 x 15 min episodes
|---------|-------------------| 30 min + 1 hour episodes
|-----------------------------| 1h30 episode
|----|---------|---------|----| 2 x 15 min + 2 x 30 min episodes
Alignment is automatic.
Note: with QVBoxLayout and QHBoxLayout, the previous example would have been (without specific code):
0 15 30 45 60 75 90
|----|----|----|----|----|----|
|--------------|--------------|
|-----------------------------|
|------|-------|-------|------|
Notice how all cells in a row have the same size. This can be changed, but requires you to handle cell size manually...
I recommend QGridLayout because it will keep everything aligned easier than if you used a bunch of QBoxLayouts. With QGridLayout, your addWidget and addLayout methods have an optional columnSpan that you can make good use of. For example, you could have each column be 15 minutes, so a 45 minute show would span 3 columns.
You don't typically implement scrolling with QLayouts. I don't recommend it. Instead you can set QGridLayout's rowMinimumHeight and rowMaximumHeight to the same value so that you can ensure each row is the same height, then do the same for columns. Then you can put the layout (and encasing widget) into a QAbstractScrollArea and set the step size of the scroll bars to the row and column heights, so that as you scroll, it steps from channel to channel and time segment to time segment, rather than scrolling continuously.
Related
Is there a way to tell the # of columns that are created in a SwiftUI Adaptive Grid? For example the left view with an iPhone 14 Pro has 4 buttons across, while an iPhone 12 mini on the right fits 3 buttons.
If I can tell the # of items, then I can tell if there are fewer items than can be displayed on a full screen, then create a LazyHStack for the % resulting leftover items which presents the additional items centered. The smaller iPhone with 3 buttons across shows the effect I'm trying to achieve - which I can do if I fix GridItems to 3 columns. I'd like this to be dynamic so, for example, I can tell I have 3 of 4 buttons across & can put them all in the single, centered LazyHStack of my last column.
Thanks for advice!
I am using wxtreelistctrl to construct a tree and I want to store 4 columns in it, but while displaying I want to display only 2 columns. Is there any way I can do this?
With wxTreeListCtrl this is not directly supported, but you could set column width to 0 as a quick and dirty hack.
With wxDataViewCtrl itself, you can perfectly well show just some of the columns of your wxDataViewModel in the GUI control.
I am writing a central display widget, it contains many small cell widgets where each of them have some QLabels to display some text info.
I have about 100 QLabels in total. And each of them is updated in around 2 Hz.
Then my GUI thread becomes very lag...
What is the possible solutions out there?
The 100 QLabels are in a scroll area btw.
As you use a scroll area, I guess, you don't show all 100 labels at a time, right? Than you have to update only those labels that are visible. For that reason I would suggest using Qt Model-View-Controller (MVC) classes, such as QTableView, etc. That will ensure that only visible items (cells) will be processed, and performance wise this approach will be much efficient.
I have a Grid and there are 7 columns and 6 rows. And there is listbox added for each row and column combination. Each list box is having arround 5 items (as default is 5, not increase above that). Each listbox item is having complex template. If i bind whole data then it takes 4 to 5 second to load. So to make fast loading, i am binding only that listbox which is visible on screen. so now it loads fast within a second. But when i scroll down, then the another data loads. But the scroll viewer lags for a second. So how can i scroll smothely ?
Any idea ?
When I use iCarousel type linear, and wrap is true. I am getting an UI like below:
The problem, I am facing is at the top the number 998 UI is broken, but I want visible 998 number without increasing iCarousel height. So, how can I achieve this? and one more thing I don't bother about UI might break for number 2, if I want a visible 998 number.
There are two reasons why your carousel item is cut off:
1) Your carousel view is not vertically centered in the window. If you center it, 0 will be dead centre and 998 and 2 will both be cut off, but equally
2) You need to set the item view size to exactly fit your view. You're currently using the default images that come with the example project which are 200x200 pixels in size. Presumably you will eventually replace these with your own views. When you do, make sure the size of those views is an exact division of the height of your window, so for example if your windows is 1024 pixels high, and you want to show 5 views, then they need to be 1024/5 pixels high (204.8 px). Obviously that's not a nice number, but you can make them a bit smaller so that they are a nice round number and then adding some spacing between them using the carousel delegate method.