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. QScrollArea with a QLabel isn't auto scrolling
Forum Update on Tuesday, May 27th 2025

QScrollArea with a QLabel isn't auto scrolling

Scheduled Pinned Locked Moved Unsolved General and Desktop
qscrollarea
1 Posts 1 Posters 1.1k Views 1 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.
  • A Offline
    A Offline
    AlaaM
    wrote on 16 Feb 2016, 13:18 last edited by
    #1

    It's a bit long so please bear with me.

    I have a QLabel with text that's wider than the window size.
    The QLabel is inside a horizontal QScrollArea:

    scrollArea->setWidget(label);
    scrollArea->setFixedSize(WINDOW_WIDTH , BUTTON_HEIGHT);
    

    I navigate through letters in the QLabel by the keyboard arrow keys, setting selection on each letter by QLabel::setSelection().
    For example say I have the text abcdefghijklmno|pqrstuvwxyz . The pipe (|) indicates the end of the window - it's not really there. So currently only the letters {a...o} are visible. I start by setting selection on the letter a. Then I press the right arrow key and set selection on the letter b, and so on...
    Say I reached letter o :
    abcdefghijklmno**|pqrstuvwxyz**
    I expect the scrollArea to scroll right on the next click. But it doesn't. Namely when the letter p is selected, I need the scrollArea to scroll to make it visible.

    I tried ensureVisible() but it's not working for me - the scrollArea won't scroll whatever I passed to ensureVisible(). For example I tried ensureVisible(WINDOW_SIZE+20 , 0) or ensureVisible(20 , 0) and neither of them worked. I guess ensureVisible() is not what I need.

    Of course I can count letters and when I reach say the 14th letter, I scroll it. But that's not good because say I scroll to letter 20, then go back to 13 - the next right click shouldn't scroll, but it would.

    Anyway, what I'm currently doing is keeping a counter for the font width up until the selected letter. I update it on every right/left click (right click: increment counter by width , left click: decrement counter by width) - and using that I decide when to scroll. It's good but it's not perfect.
    Any other ideas? Preferably something neat and automatic, not a workaround.

    Thanks!

    1 Reply Last reply
    0

    1/1

    16 Feb 2016, 13:18

    • Login

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