Skip to content
QtWS25 Last Chance
  • 0 Votes
    6 Posts
    2k Views
    SGaistS
    The Basic Drawing Example shows that. In your case, you'd likely just have to paint your image using the correct scaling information.
  • 0 Votes
    8 Posts
    2k Views
    mrjjM
    @Arash-Shirvan well i didnt get issue as im using Designer that comes with a widget in place ( for scrollArea) . so i missed the fact you didnt add widget and layout to that. :)
  • Issues with QScrollArea and custom widget

    Solved General and Desktop qscrollarea
    23
    0 Votes
    23 Posts
    9k Views
    kshegunovK
    @Joel-Bodenmann said in Issues with QScrollArea and custom widget: Too bad those people didn't teach you how to write nice code though :p This is all a fault of my own, sadly, but hey life's not all roses ... :) Thank you for your help guys, much appreciated! You are welcome. Now go and make us proud! ;D
  • 0 Votes
    2 Posts
    2k Views
    Stefan ScherfkeS
    The solution was (surprisingly) simple: Use the FlowLayout’s heightChanged signal to update the minimum height of the container (the ScrollArea’s widget). Here is a working example: """ PyQt5 port of the `layouts/flowlayout <https://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html>`_ example from Qt5. """ from PyQt5.QtCore import pyqtSignal, QPoint, QRect, QSize, Qt from PyQt5.QtWidgets import QLayout, QSizePolicy, QSpacerItem class FlowLayout(QLayout): """A ``QLayout`` that aranges its child widgets horizontally and vertically. If enough horizontal space is available, it looks like an ``HBoxLayout``, but if enough space is lacking, it automatically wraps its children into multiple rows. """ heightChanged = pyqtSignal(int) def __init__(self, parent=None, margin=0, spacing=-1): super().__init__(parent) if parent is not None: self.setContentsMargins(margin, margin, margin, margin) self.setSpacing(spacing) self._item_list = [] def __del__(self): while self.count(): self.takeAt(0) def addItem(self, item): # pylint: disable=invalid-name self._item_list.append(item) def addSpacing(self, size): # pylint: disable=invalid-name self.addItem(QSpacerItem(size, 0, QSizePolicy.Fixed, QSizePolicy.Minimum)) def count(self): return len(self._item_list) def itemAt(self, index): # pylint: disable=invalid-name if 0 <= index < len(self._item_list): return self._item_list[index] return None def takeAt(self, index): # pylint: disable=invalid-name if 0 <= index < len(self._item_list): return self._item_list.pop(index) return None def expandingDirections(self): # pylint: disable=invalid-name,no-self-use return Qt.Orientations(Qt.Orientation(0)) def hasHeightForWidth(self): # pylint: disable=invalid-name,no-self-use return True def heightForWidth(self, width): # pylint: disable=invalid-name height = self._do_layout(QRect(0, 0, width, 0), True) return height def setGeometry(self, rect): # pylint: disable=invalid-name super().setGeometry(rect) self._do_layout(rect, False) def sizeHint(self): # pylint: disable=invalid-name return self.minimumSize() def minimumSize(self): # pylint: disable=invalid-name size = QSize() for item in self._item_list: minsize = item.minimumSize() extent = item.geometry().bottomRight() size = size.expandedTo(QSize(minsize.width(), extent.y())) margin = self.contentsMargins().left() size += QSize(2 * margin, 2 * margin) return size def _do_layout(self, rect, test_only=False): m = self.contentsMargins() effective_rect = rect.adjusted(+m.left(), +m.top(), -m.right(), -m.bottom()) x = effective_rect.x() y = effective_rect.y() line_height = 0 for item in self._item_list: wid = item.widget() space_x = self.spacing() space_y = self.spacing() if wid is not None: space_x += wid.style().layoutSpacing( QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Horizontal) space_y += wid.style().layoutSpacing( QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Vertical) next_x = x + item.sizeHint().width() + space_x if next_x - space_x > effective_rect.right() and line_height > 0: x = effective_rect.x() y = y + line_height + space_y next_x = x + item.sizeHint().width() + space_x line_height = 0 if not test_only: item.setGeometry(QRect(QPoint(x, y), item.sizeHint())) x = next_x line_height = max(line_height, item.sizeHint().height()) new_height = y + line_height - rect.y() self.heightChanged.emit(new_height) return new_height if __name__ == '__main__': import sys from PyQt5.QtWidgets import QApplication, QPushButton, QScrollArea, QVBoxLayout, QWidget, QGroupBox app = QApplication(sys.argv) container = QWidget() container_layout = QVBoxLayout() for i in range(2): g = QGroupBox(f'Group {i}') l = FlowLayout(margin=10) l.heightChanged.connect(container.setMinimumHeight) g.setLayout(l) l.addWidget(QPushButton('Short')) l.addWidget(QPushButton('Longer')) l.addWidget(QPushButton('Different text')) l.addWidget(QPushButton('More text')) l.addWidget(QPushButton('Even longer button text')) container_layout.addWidget(g) container_layout.addStretch() container.setLayout(container_layout) w = QScrollArea() w.setWindowTitle('Flow Layout') w.setWidgetResizable(True) w.setWidget(container) w.show() sys.exit(app.exec_())
  • 0 Votes
    4 Posts
    2k Views
    mrjjM
    @Rohith Hi Im not sure what goes wrong. I guess you are still not using the RIGHT click layout menu ? Do not drag layouts from left box. Please see this video. https://www.dropbox.com/s/t3icclcqb446jkm/scroll.mp4?dl=0
  • 0 Votes
    4 Posts
    2k Views
    SGaistS
    AFAIK, the Qt 4.8 series has no release officially supporting such a recent version of macOS. Therefore you may have surprises. Note that Qt 4 has reached end of life so unless you are locked to that version, you should really consider updating to Qt 5 which is now at it's 5.9.0 release.
  • 0 Votes
    4 Posts
    2k Views
    T
    @SGaist Thanks I managed to do it this way.
  • 0 Votes
    3 Posts
    1k Views
    T
    @the_ no it is Qt::ScrollBarAsNeeded.but scrolbar appears correctly after I resize the main widget even with 1 px.
  • 0 Votes
    4 Posts
    4k Views
    J
    @raven-worx: while I'm not sure it is the right solution for what @tokafr wants to do, he can take ownership of the vertical scrollbar and have some influence this way. I have done it before that way. @tokafr: Instead of trying to influence the hidden layout of the QTableView, you could mask the space between the header view and the vertical scrollbar to make it look like it being part of the header view. Stylesheets are probably the best place to try.
  • How to adjust scroll area as per widgets?

    Unsolved General and Desktop qscrollarea qgroupbox
    2
    0 Votes
    2 Posts
    827 Views
    raven-worxR
    @NIXIN have you set QScrollArea's widgetResizeable property set to true? If not it should be enough to resize the QScrollArea's content widget to it's sizeHint.
  • QComboBox long item text breaks layout

    Unsolved General and Desktop qscrollarea qcombobox qformlayout
    4
    0 Votes
    4 Posts
    4k Views
    the_T
    @Rondog I was already thinking of setting the maximum width for each combobox but when creating the comboboxes I dont know the width of the scrollareas viewport. @SGaist Will try that, seems to be the more nice solution :) Thanks
  • Reduce painting area of qwidget.

    Unsolved General and Desktop qwidget qtableview qscrollbar qscrollarea
    2
    0 Votes
    2 Posts
    1k Views
    mrjjM
    hi I have never tried this myself so might be silly question, If you set the qtableview to always show horz scrollbar (Qt::ScrollBarPolicy) and then replace it with your own. the size should fit? Or is because your new scrollbar is bigger? (than the std one) the docs says "When a scroll bar becomes visible again, the viewport shrinks in order to make room for the scroll bar." so it should just work by auto. So I wonder if the custom bar dont give correct size info?
  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • QScrollArea with a QLabel isn't auto scrolling

    Unsolved General and Desktop qscrollarea
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • Custom widget in QScrollArea

    Solved General and Desktop qt4.8.6 qscrollarea
    4
    0 Votes
    4 Posts
    3k Views
    E
    The solution is: painter.fillRect(QRect(0,0, width(), height()), Qt::red); geometry() delivers negative x/y values.
  • Deleting data from a QScrollArea

    Solved General and Desktop qscrollarea
    16
    0 Votes
    16 Posts
    9k Views
    mrjjM
    Hi "allSubLayouts.at(i)->*itemAt*(j)->*widget*();" made my brain hurt :) Well since u are not deleting any widgets, u will use more and more memory, but since they are still owned by layout, it will be free when application ends.
  • 0 Votes
    9 Posts
    4k Views
    SGaistS
    Hi, You can try to use ensureWidgetVisible by calling it if e.g. the scroll bar has not been moved for a certain amount of time. Hope it helps
  • 0 Votes
    11 Posts
    8k Views
    mrjjM
    @marlenet15 instructionsScrollArea1 and ReplaceNow() should be in same object or same file at least. that what scope means. so where is instructionsScrollArea1 declared and where is void ReplaceNow() ? Also the * in removeWidget(*instructionsScrollArea1); is wrong. If possible,post whole code here and its easier for us to help.