Getting rid of blank area at the bottom of a QListWidget - qt

I'm using QListWidget with setItemWidget and when adding items to the list and scrolling down to the bottom I get this result:
So there's an area which is completely blank at the bottom (not selectable, in the image above the last item in the list has been selected)
How can I get rid of this blank area at the bottom of the list?
Please note that the height of the rows can be different within a list
Grateful for help and with kind regards,
Tord

It's possible to change the type of vertical scrolling that is done for list by using setVerticalScrollMode for the QListWidget so that the scrolling is done per pixel (instead of per item which is the default):
self.list_widget.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
The result is that rows that are in the top-most part of the QListWidget box can be drawn only in part, which in turn means that the blank area that exists when scrolling per item will disappear:
Reference documentation:
https://doc.qt.io/qt-5/qabstractitemview.html#verticalScrollMode-prop

I'm using exactly the same approach and I get rid of the blank area by creating a widget that contains my QListWidget and use :
listwidget.setFixedSize(widget.width(), listwidget.sizeHintForRow(0) * listwidget.count() + 2 * listwidget.frameWidth())
listwidget is you QListWidget object
widget is the widget that contains your QListWidget object

Related

How to easily recognize searched item in a dense QGraphicsScene?

I have a QGraphicsScene with many QGraphicsItem like circle, rectangle, polylines, arc etc.
Every QGraphicsItem has a name. And I have a Search feature which highlights searched items using that name. When scene contains fewer items, highlighted items are seen properly. But when scene contains many items ( 100 + ) then identifying the highlighted item becomes difficult. For that I need to scroll up - down or left - right to check where is that highlighted item is.
So I want my highlighted item to be easily recognizable.
For that I was suggested, some approach like
Take searched item in front
Or
Add some marker
But I do not know, how to implement it , which Qt class should I use etc.
QGraphicsScene displays items depending on their stacking, i.e., when you call .items(), the first item in the QList is the topmost item on the scene.
The ordering of the items is depending on their respective Z-values which you can set for the QGraphicsItem by calling .setZValue()
You can read more about this on the following link: https://doc.qt.io/qt-5/qgraphicsitem.html#sorting
As for your question on how to put them in front. If you implemented your own children classes of QGraphicsItem, you can add a method or a slot to toggle them "on-top". E.g., all of the items usually have a Z-order of 0, so your method could just set it to 1 when the item is highlighted and revert it to 0 when it's not.

How to delete the space between QLabel and QLineEdit

I have a QDialog window like this and I want to delete the space between 'Length', 'n', 'm' and corresponding QLineEdit input boxes. How can I achieve that ?
If you use gridlayout, I am not sure why your output looks like that. Generally Qt will not leave huge empty space like that, There are three possibility I can think of:
You have many SPACE after Length:, M: or N:
The layoutHorizontalSpacing is too large in your grid manager.
The layoutColumnStretch was set to in favor of label in your grid manager, should be "0,0", not "1,0". I mean, stretch of Label should not be higher than lineedit.
Still, I would use a simple form layout in your application.
All you need to do is reset the alignment of the labels:
label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlighVCenter)
This can also be done in via the Property Editor in Qt Designer.
You have to decide what to do with the space you want to remove :
Reduce the whole widget : it depends on the surrounding layout, adding an horizontal layout on right or left of it will put the space out of your widget.
Space on the left of your labels : you can align the label text to the right as ekhumoro suggested, or directly reduce and align to the right the whole frame by adding an horizontal spacer on its left (in the surrounding layout).
Space on the right of your line-edits : like above you can add horizontal spacers or reduce and align the frame.
Expand the line-edits : remove their fixed width (default horizontal policy is expanding) or set a bigger one.
The point is : the space has to be somewhere except if you reduce the parent widget or enlarge some the inner widgets. Size-policy is useful to tell which widget should take the available space, spacers are useful to let empty space between widgets.

Widget or layout to fill parent

What I'm trying to accomplish is a very simple and straight forward need, or I thought, but for the life of me, I can't seem to find a way to do it.
In my qt application I want to be able to make a widget or a layout fill the entire space of the parent widget.
For example, let's say I want to have a label with a fixed height and beneath it a stacked widget which occupies the rest of the height of the window.
Here's what I do in the qt-creator designer:
drag a label to the form
drag a stacked widget to the form
select both of them and then right click > lay out > lay out vertically
select the verticalLayout object and in the layoutStretch property have 0,1
Now, how do I make the verticalLayout occupy all of the width/height of the centralWidget?
Nothing seems to work for me.
Thanks.
You've merely put two widgets in a layout, but you also need a layout on their parent widget - on the form. Here's what you should do instead:
Drag any number of widgets to the parent widget (the form). Arrange them roughly the way you want them to be once laid out.
Right click on the form. Select "Lay out >" submenu.
Choose the desired layout from the menu: horizontal, vertical, grid, etc.

How can I get rid of vertical spacing of empty rows in a QGridLayout in Qt?

So I have a dialog that consists of one QGridLayout that has two columns of widgets (labels and comboboxes). Depending on the selections of the comboboxes some rows might be hidden.
I figured out that having the dialog call self.layout().setSizeConstraint(QLayout.SetFixedSize) as it shows/hides the comboboxes would make the dialog change size accordingly.
But then I realized that the layout was still showing the vertical spacing of empty rows, thus making the dialog show too much space here and there.
How can I get rid of this? Is there a way to have the layout resize to show only vertical spacing of rows that have visible widgets?
I think I found the solution. Using QVBoxLayout instead of QGridLayout somehow makes widgets and their vertical spacing go away when a widget is hidden.
You might need to use QLayout::takeAt ( int index ) to take out the item, once the visibility is set to false & use QLayout::addItem ( QLayoutItem * item ) when you need it back in your layout.
Keep in mind that if an item is removed, other items will be renumbered. So you have to plan what you do accordingly. Refer the documentation .

Flex horizontal tile list

I am using a horizontal tilelist in flex to display an image gallery with only one item in horiz. tilelist being shown at a time. I have next and previous buttons on both sides.
The problem is I want to display a particular item/image in that list when user clicks on a thumb image from another thumbimages tilelist at bottom.
I used someTilelist.selectedIndex property but it just selects that particular index in list, it does not show that particular item/image. I want the list to show that particular image, not just select it. Please take note that the horiz. tilelist shows only one image at time.
tilelist.scrollToIndex(index);

Resources