Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. scroll a QWidget with children
Forum Updated to NodeBB v4.3 + New Features

scroll a QWidget with children

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 472 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vendelin
    wrote on last edited by
    #1

    Hi,

    I'd like to create an app with scrolling ability. The central widget is based on QWidget, that has some "slides" inside a QHBoxLayout. There are a lot of small details that I think are not important for the question, but feel free to ask in case.

    So the central widget can scroll horizontally, but I didn't want scroll bars at all, so I'm using the built in

    void QWidget::scroll(int dx, int dy)
    

    function to scroll the content. Mainly it works as expected, but there's a problem. Each child slide has a QLabel on them, and when I change the text with

    void QLabel::setText(const QString &)
    

    It moves the scroll position to the left side of the container. No matter if that slide is visible or not, no matter which label, it always jumps to the far left. Both on linux desktop and android.

    I think it's something with a dirty unpainted area, but I can't fix it anyhow. Please help!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi and welcome to devnet,

      You should add which version of Qt you are using, which Linux distribution and Android version.

      You should also provide a minimal compilable example that shows the behaviour so other people can take a look at it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi and welcome to the forums.
        If you scroll the labels inside a layout , i assume what is happening is that when setting text,
        the layout recalculate to take account the new text.

        At least that idea was very fast to reproduce.
        alt text

        And the reason i think its that is because requesting it to recalculate reset labels positions.
        ui->verticalLayout->invalidate();
        ui->verticalLayout->activate();


        Could you not just use a ScrollArea and hide the bars ?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vendelin
          wrote on last edited by
          #4

          Hi,

          I'm using currently latest Qt 5.11.1-1 on my Arch linux. I'm using Android 7.1.2 .

          I looked at the code of QScrollArea, and saw that it uses

          void QWidget::move(const QPoint &)
          

          in the background for the viewport widget. Replacing scroll into move wasn't a good idea though in all of the cases, but a mixture of them will be fine I guess. I think it will be okay soon, but if I don't succeed, I'll replace the whole thing with a QScrollArea.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved