Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. qscrollarea
    Log in to post

    • UNSOLVED QScrollArea - minimum width controlled by content? - remove horizontal bars?
      General and Desktop • qscrollarea • • Dariusz  

      1
      0
      Votes
      1
      Posts
      33
      Views

      No one has replied

    • UNSOLVED QScrollArea
      General and Desktop • qt creator qscrollarea image display show images • • Sai Raul  

      5
      0
      Votes
      5
      Posts
      71
      Views

      @Sai-Raul Look : https://doc.qt.io/qt-5/qscrollarea.html Whitout Qlablel.. There is QGraphicsScene with QGraphicsView.
    • UNSOLVED QLabel image load
      General and Desktop • c++ qlabel qscrollarea show images • • Sai Raul  

      8
      0
      Votes
      8
      Posts
      149
      Views

      @Sai-Raul ok. but Qlabels only likes pixmaps.
    • UNSOLVED QGraphicsView vs QScrollArea for lots of primitive geometry rendering
      General and Desktop • opengl qgraphicsview qscrollarea • • SandSnip3r  

      1
      0
      Votes
      1
      Posts
      113
      Views

      No one has replied

    • SOLVED QVBoxLayout just stacking widgets on top of each other
      General and Desktop • widget qscrollarea list qvboxlayout qwidgetlist • • Erika_Butler  

      3
      0
      Votes
      3
      Posts
      531
      Views

      @jsulm Fortunately, I just solved it. I should not have specified the VerticalWidgetList class as the parent of the widgets added. Apparently, when you add it to the layout, the widgets added get some sort of other parent class. I still nullptr out the widget in the takeWidget() function, however, as control of it should pass to the function receiving the return value. When I got rid of setting the parent in the addWidget() and insertWidget() functions, it now works properly. I do wonder if I should still delete the child widget in removeWidget() and removeWidgetAt() after removing it from the layout. Or do I need to set the parent to nullptr before deleting it? When my program used clearWidgets(), which calls removeWidget(), there was no problem. It works now! This is the source code now: verticalwidgetlist.h #ifndef VERTICALWIDGETLIST_H #define VERTICALWIDGETLIST_H #include <QScrollArea> #include <QVBoxLayout> #include <QWidgetList> class VerticalWidgetList : public QScrollArea { Q_OBJECT public: explicit VerticalWidgetList(QWidget *parent = nullptr); bool addWidget(QWidget *child); void clearWidgets(); bool insertWidget(int index, QWidget *child); bool removeWidget(QWidget *child; bool removeWidgetAt(int index); QWidget *takeWidget(int index); int widgetAt(QWidget *child) const; private: QWidget *m_central; QVBoxLayout *m_layout; QWidgetList m_list; }; #endif // VERTICALWIDGETLIST_H verticalwidgetlist.cpp #include "verticalwidgetlist.h" VerticalWidgetList::VerticalWidgetList(QWidget *parent) : QScrollArea(parent) , m_central(new QWidget) , m_layout(new QVBoxLayout(m_central)) , m_list() { setWidget(m_central); setWidgetResizable(true); } bool VerticalWidgetList::addWidget(QWidget *child) { if(child == nullptr) return false; m_layout->addWidget(child); m_list.append(child); return true; } void VerticalWidgetList::clearWidgets() { while(m_list.count()) { QWidget *widget = m_list[0]; removeWidget(widget); } } bool VerticalWidgetList::insertWidget(int index, QWidget *child) { if(index < 0 || index > m_list.count()) return false; if(child == nullptr) return false; m_layout->insertWidget(index, child); m_list.insert(index, child); return true; } bool VerticalWidgetList::removeWidget(QWidget *child) { if(child == nullptr) return false; m_layout->removeWidget(child); int index = widgetAt(child); m_list.removeAt(index); delete child; return true; } bool VerticalWidgetList::removeWidgetAt(int index) { if(index < 0 || index >= m_list.count()) return false; QWidget *widget = m_list.takeAt(index); m_layout->removeWidget(widget); delete widget; return true; } QWidget *VerticalWidgetList::takeWidget(int index) { if(index < 0 || index >= m_list.count()) return nullptr; QWidget *widget = m_list.takeAt(index); m_layout->removeWidget(widget); widget->setParent(nullptr); return widget; } int VerticalWidgetList::widgetAt(QWidget *child) const { if(child == nullptr) return -1; return m_list.indexOf(child); } EDIT: If anyone tried the source code up until this point, in this post, try again. I was rearranging removeWidget() and removeWidgetAt(), which I realized were mismatched in terms of their parameters. It's good now!
    • UNSOLVED Aligning QLabel center in QScrollArea causes wrong coordinate reading
      General and Desktop • qscrollarea alignment qlabel position • • lansing  

      6
      0
      Votes
      6
      Posts
      296
      Views

      My sampleColor function was called from the QScrollArea::mouseMoveEvent and the QPoint mousePos was pass in from the mouseEvent there. What I'm suspecting is that when the image was loaded, the default alignment AlignTop & AlignLeft kicked in, then the mouseMoveEvent followed and the sampleColor function somehow took a snapshot of the imageLabel, before the AlignCenter setting in the constructor. That's why my mouse was still seeing the image at the pre-aligncenter position in the snapshot.
    • UNSOLVED QTabWidget, how to load some data in QScrollArea from a database inside QTabWidget
      General and Desktop • database sqlite qtabwidget qscrollarea • • moslehuddin  

      2
      0
      Votes
      2
      Posts
      146
      Views

      @moslehuddin You should be more precise when asking a question. What exactly are you asking? How to get data from a database? How to show it? Both? How to use QScrollArea? Qt SQL: https://doc-snapshots.qt.io/qt5-5.14/qtsql-index.html How to show the data: https://doc.qt.io/qt-5/qsqltablemodel.html and https://doc.qt.io/qt-5/qtableview.html How to use QScrollArea: https://doc.qt.io/qt-5/qscrollarea.html
    • UNSOLVED QScrollArea not expanding when QPixmap is loaded
      General and Desktop • qlabel qpixmap qscrollarea • • Conical  

      3
      0
      Votes
      3
      Posts
      164
      Views

      Hi, How did you set the QLabel on your QScrollArea ? If you put it in a layout on the scroll area then that's wrong.
    • UNSOLVED QScrollArea width to expand according to child
      General and Desktop • qscrollarea qsizepolicy • • Dariusz  

      8
      0
      Votes
      8
      Posts
      696
      Views

      @Dariusz Hi im not sure that is possible as the ScrollArea widget is the one affected by layout options and not the actual ScollArea. Maybe you get lucky and someone else knows a trick to this. I have seen QLabels with images scale the dialog they are in but not sure it also works from within a scrollarea since its size will never be affected by the layouts.
    • SOLVED QScrollArea and transparent scroll bar
      General and Desktop • qt5 qscrollarea qscrollbar • • Alairion  

      3
      0
      Votes
      3
      Posts
      404
      Views

      Hi, thanks you for answer. The scroll area in my application is inside another widget, the main window, and it has an illustrated background. The problem is for main window not the content of the scroll area. Anyway, I found a workaround, I set the same background for the main window and the scroll bar, so the scroll bar is opaque but looks transparent. I still wonder why is there this strange behaviour with the scroll bar, but this topic can be considered as solved as I found a way to get around this.
    • SOLVED QScrollArea: Avoiding initial delay to scrolling
      General and Desktop • qscrollarea • • VPaa 0  

      3
      0
      Votes
      3
      Posts
      234
      Views

      @sgaist Thanks for the comment. I got it working albeit the solution may be a little kludgy; I couldn't directly detect whether user's mouse click is upon one of the arrow buttons of a scrollbar, so I used a logic like this: When a signal fires to indicate a single-step movement to either direction, call QAbstractSlider::setRepeatAction to override the normal repetition pattern by a pattern without the delay. However, that override must be done only once per mouse-press, so I overrode QScrollBar::mousePressEvent so as to set a "sensitivity flag" for that purpose.
    • UNSOLVED Scaling pixmap images in qscrollarea
      General and Desktop • qlabel qpixmap qscrollarea • • rjmoses  

      4
      0
      Votes
      4
      Posts
      242
      Views

      @rjmoses Yes it will scale all images to match IconSize.
    • UNSOLVED Disable slider of scrollbar in scrollarea
      General and Desktop • qscrollarea qscrollbar • • AlexanderB  

      6
      0
      Votes
      6
      Posts
      1325
      Views

      @AlexanderB Hi If you look here https://code.woboq.org/qt5/qtbase/src/widgets/styles/qwindowsstyle.cpp.html in 1894 void QWindowsStyle::drawComplexControl you can see the use of QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget); QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget); I assume you can get the various parts this way, even you changed it using stylesheet.
    • UNSOLVED Scrollbar appearing/disappearing infinitely -> override calculation used to display scrollbar in QScrollArea
      General and Desktop • qscrollarea qscrollbar • • BryceBeagle  

      4
      0
      Votes
      4
      Posts
      416
      Views

      I was thinking about the widgets. By the way, how are you adding them to the QScrollArea ?
    • UNSOLVED Disable scroll area in QTableView/QTableWidget
      General and Desktop • qtableview qscrollarea scrollarea scroll viewport • • Maluna34  

      4
      0
      Votes
      4
      Posts
      3969
      Views

      Unfortunately it seems that it's not enough to trigger the scrollbar of the parent. The solution I found is to set the fixedWidth of the table like this : int size{ 0 }; for (int i = 0; i < table->columnCount(); ++i) size += table->columnWidth(i); table->setFixedWidth(size);
    • UNSOLVED ImageViewer QLabel/QScrollArea top and bottom margins?
      General and Desktop • qlabel qscrollarea qguiapplication • • forlorn  

      6
      0
      Votes
      6
      Posts
      1157
      Views

      The Basic Drawing Example shows that. In your case, you'd likely just have to paint your image using the correct scaling information.
    • SOLVED problem in adding many Widgets to QScrollArea and keep the size gentle
      General and Desktop • qscrollarea • • Arash Shirvan  

      8
      0
      Votes
      8
      Posts
      1054
      Views

      @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. :)
    • SOLVED Issues with QScrollArea and custom widget
      General and Desktop • qscrollarea • • Joel Bodenmann  

      23
      0
      Votes
      23
      Posts
      5784
      Views

      @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
    • SOLVED QScrollArea with FlowLayout widgets not resizing properly
      General and Desktop • qscrollarea flowlayout • • Stefan Scherfke  

      2
      0
      Votes
      2
      Posts
      1363
      Views

      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_())
    • SOLVED How to program QScrollArea thorugh QtCreator
      General and Desktop • qtcreator qscrollarea qlayout • • Rohith  

      4
      0
      Votes
      4
      Posts
      1443
      Views

      @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
    • SOLVED wheelEvent is calling twice on MAC.
      General and Desktop • qscrollarea qscrollbar qwheelevent • • tokafr  

      4
      0
      Votes
      4
      Posts
      1057
      Views

      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.
    • SOLVED QScrollBar acts differently when pressing arrow keys and scrolling.
      General and Desktop • qscrollarea qscrollbar qslider • • tokafr  

      4
      0
      Votes
      4
      Posts
      1534
      Views

      @SGaist Thanks I managed to do it this way.
    • UNSOLVED Scrollbar doesn't appear on QListWidget when item starts on visible area.
      General and Desktop • qlistview qlistwidget qscrollarea qscrollbar • • tokafr  

      3
      0
      Votes
      3
      Posts
      1131
      Views

      @the_ no it is Qt::ScrollBarAsNeeded.but scrolbar appears correctly after I resize the main widget even with 1 px.
    • UNSOLVED How to set top margin to QScrollBar in QTableView.
      General and Desktop • qtableview qscrollarea qslider • • tokafr  

      4
      0
      Votes
      4
      Posts
      2974
      Views

      @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.
    • UNSOLVED How to adjust scroll area as per widgets?
      General and Desktop • qscrollarea qgroupbox • • NIXIN  

      2
      0
      Votes
      2
      Posts
      647
      Views

      @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.
    • UNSOLVED QComboBox long item text breaks layout
      General and Desktop • qcombobox qscrollarea qformlayout • • the_  

      4
      0
      Votes
      4
      Posts
      3137
      Views

      @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
    • UNSOLVED Reduce painting area of qwidget.
      General and Desktop • qwidget qtableview qscrollarea qscrollbar • • tokafr  

      2
      0
      Votes
      2
      Posts
      831
      Views

      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?
    • UNSOLVED QScrollArea in Qml: Flickable + QQuickPaintedItem
      QML and Qt Quick • qml quick flickable qscrollarea • • alan73  

      1
      0
      Votes
      1
      Posts
      934
      Views

      No one has replied

    • UNSOLVED QScrollArea with a QLabel isn't auto scrolling
      General and Desktop • qscrollarea • • AlaaM  

      1
      0
      Votes
      1
      Posts
      974
      Views

      No one has replied

    • SOLVED Custom widget in QScrollArea
      General and Desktop • qscrollarea qt4.8.6 • • ElRudi  

      4
      0
      Votes
      4
      Posts
      2058
      Views

      The solution is: painter.fillRect(QRect(0,0, width(), height()), Qt::red); geometry() delivers negative x/y values.
    • SOLVED Deleting data from a QScrollArea
      General and Desktop • qscrollarea • • mar0029  

      16
      0
      Votes
      16
      Posts
      7402
      Views

      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.
    • UNSOLVED QScrollArea with mixed content, how to scroll that no labels or QLineedits will be cut off?`
      General and Desktop • embedded qscrollarea cut • • BluTiGeS  

      9
      0
      Votes
      9
      Posts
      3121
      Views

      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
    • replace one widget with another on a layout with a button
      General and Desktop • c++ linux qpushbutton qscrollarea qgroupbox • • marlenet15  

      11
      0
      Votes
      11
      Posts
      6076
      Views

      @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.
    • [Solved]QScrollArea Squeezes Child Widgets instead of Expanding Scrollable Area
      General and Desktop • qscrollarea qlayout • • Corpse0327  

      9
      0
      Votes
      9
      Posts
      8988
      Views

      Because it still is a QWidget and setLayout is one of the base function
    • QScrollArea odd sizes
      General and Desktop • qscrollarea qopenglwi • • Fundies  

      4
      0
      Votes
      4
      Posts
      1040
      Views

      @Fundies The Mainwindow has the size you make it in forms designer or the size you give it in code. It will not adjust size to the widgets it owns so you must do it. They adjust to it.
    • [SOLVED] scrollArea in scrollArea
      General and Desktop • qscrollarea qscrollbar • • A Former User  

      5
      0
      Votes
      5
      Posts
      1425
      Views

      ah. the _scrollAreaLayer does respect the size limits then. Good to know.