Important: Please read the Qt Code of Conduct -

[SOLVED] Set Scroll Per Item

  • Hello -

    I am trying to set the Scroll Mode to Scroll Per Item, as referenced here:

    I am using a QScrollArea, and have tried setting the mode as follows:

    @ QScrollArea *scrollArea = new QScrollArea (this);
    scrollAreaWidgetContents->setLayout (appLayout);

    scrollArea->setWidget (scrollAreaWidgetContents);
    scrollArea->setFrameShape (QFrame::NoFrame);
    scrollArea->setAlignment (Qt::AlignCenter);
    scrollArea->setAutoFillBackground (false);
    scrollArea->viewport ()->setAutoFillBackground (false);
    scrollAreaWidgetContents->setAutoFillBackground (false);

    scrollArea->QAbstractItemView::setHorizontalScrollMode (QAbstractItemView::ScrollPerItem);@

    but I get a compiler error that QAbstractItemView is not a base of QScrollArea. I am pretty new to c++ and am unsure what to make of this. I also tried:
    @scrollArea->setHorizontalScrollMode (QAbstractItemView::ScrollPerItem);@
    and get a compiler error that QScrollArea has no member names 'setHorizontalScrollMode'.

    Any help would be much appreciated.

  • The errors say it all. Take a look at the doc page you posted, you will find that QScrollArea does not derive from QAbstractItemView (far from it actually) but it is a derivative of QAbstractScrollArea.

  • So how can I set the scrollArea to scroll per item?

  • Use a QAbstractItemView sub class. QScrollArea dose not work with items it works with widgets.

    Consider reading a book "C++ GUI Programming with Qt-4 1st edition.":
    Reading a C++ book wouldn't hurt too, ass you are having problems understating simple compiler output.

    Or at least use assistant.

Log in to reply