ScrollArea intervers with expand policy
-
@buhtz said in ScrollArea intervers with expand policy:
Isn't there a solution without explicit numbers?
You can get the width of the scrollbar from QStyle:
https://forum.qt.io/topic/333/how-to-get-width-and-height-of-qscrollbars-arrow-widgets
it is not worth the trouble IMA
The best user experience is to save the geometry of the dialog the user set and restore it in dialog show . -
@mpergand said in ScrollArea intervers with expand policy:
You can get the width of the scrollbar from QStyle:
https://forum.qt.io/topic/333/how-to-get-width-and-height-of-qscrollbars-arrow-widgetsThat doesn't answer where your 20 and 200 comes from.
The 20 is the scrollbar width?
And what is the 200? If it is the height: I don't want to modify the height.
And I also don't want to calculate the width. The width is given by the content of the widget and its childs in the scrollarea.And what I wonder about:
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
I deactivated that horizontal scrollbar. So the area should "know itself" that it should expand to its full width.
-
@buhtz said in ScrollArea intervers with expand policy:
I deactivated that horizontal scrollbar. So the area should "know itself" that it should expand to its full width.
It doesn't work like that, the magic function you're looking for doesn't exist.
-
@buhtz
That's what i said:Looking at your code, in the showEvent in LanguageDialog, you can set the minimum width of the scrollArea to the width of languageWdget.
and yes i missed this easy way:
scrollbar_width = self._scroll.verticalScrollBar().sizeHint().width()I'm not sure, sizeHint() is relevant here.
def _calculate_scroll_area_width(self): widget_width = self._scroll.widget().sizeHint().width() scrollbar_width = self._scroll.verticalScrollBar().sizeHint().width() return widget_width + scrollbar_width def showEvent(self, e): super().showEvent(e) self._scroll.setMinimumWidth(self._calculate_scroll_area_width())
I know nothing about python, but it looks OK to me.
-
@buhtz said in ScrollArea intervers with expand policy:
@ChrisW67 said in ScrollArea intervers with expand policy:
Could I suggest that a QListWidget (or QListView and model) may be a better solution for this list.Might be technical better. But I want to present my users how many languages I do support. ;) The dialog need to be a bit "boom & bling bling". ;)
This is the sort of thing I had in mind. It resizes itself to fit as much space as is available, show as many entries as possible, and does not have the child resizing its parent (i.e. the tail wagging the dog).
#include <QApplication> #include <QWidget> #include <QLabel> #include <QListWidget> #include <QListWidgetItem> #include <QVBoxLayout> int main(int argc, char **argv) { QApplication app(argc, argv); QWidget widget; QListWidget *list = new QListWidget(&widget); list->setWrapping(true); list->setGridSize(QSize(100, 20)); list->setFlow(QListView::LeftToRight); list->setResizeMode(QListView::Adjust); for (int i = 0; i< 52; ++i) { QListWidgetItem *item = new QListWidgetItem(QString("Language %1").arg(i), list); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setCheckState(Qt::Unchecked); } QLabel *label = new QLabel("Resize me", &widget); QVBoxLayout *layout = new QVBoxLayout(&widget); layout->addWidget(list); layout->addWidget(label); widget.show(); return app.exec(); }
-
Based on your example I'm not sure how you realized the multi columns. I thought it was setWrapping(True) and setGridSize(). But it does not work in my example where I try to create a 2 columns with 2 rows.
#!/usr/bin/env python3 import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import * class CenteredDialog(QDialog): def __init__(self): super().__init__() wdg = QListWidget(self) wdg.setWrapping(True) wdg.setResizeMode(QListView.Adjust) wdg.setFlow(QListView.TopToBottom) wdg.setGridSize(QSize(2, 2)) for idx in range(1, 3): wdg.addItem(f'item {idx}') # Button "Apply" button = QDialogButtonBox(QDialogButtonBox.Apply) button.clicked.connect(self.accept) # Dialog layout layout = QVBoxLayout(self) layout.addWidget(wdg) layout.addWidget(button) if __name__ == "__main__": app = QApplication(sys.argv) dlg = CenteredDialog() dlg.show() sys.exit(app.exec())