Results 1 to 6 of 6

Thread: QAbstractScrollArea scrollbar positions

  1. #1
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default QAbstractScrollArea scrollbar positions

    I have a QTreeView subclass in which I would like to obtain positions of it's scrollbars (if any). So I do:

    Qt Code:
    1. qDebug() <<
    2. horizontalScrollBar()->mapToParent(horizontalScrollBar()->pos()) <<
    3. verticalScrollBar()->mapToParent(verticalScrollBar()->pos());
    To copy to clipboard, switch view to plain text mode 

    The result is always (0,0), with or without the map at runtime. Please help.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractScrollArea scrollbar positions

    pos() is already in the parent's coordinate space. It's equivalent to:
    Qt Code:
    1. horizontalScrollBar()->mapToParent(QPoint(0,0));
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: QAbstractScrollArea scrollbar positions

    Thanks, but even without the map, as I wrote, the result is QPoint(0, 0). Are the QAbstractView's scrollbars part of the viewport, or are they outside of them? Basically, for testing purposes I'd like to do:

    Qt Code:
    1. QPainter painter(this);
    2. painter.fillRect(rect(), Qt::yellow);
    To copy to clipboard, switch view to plain text mode 

    Of course, this doesn't work because of the QAbstractScrollArea. So how could I erase the background of QAbstractViewItem manually?

    EDIT:
    Would it be possible to filter paint events of the viewport() or the both *ScrollBar()s and do some painting before forwarding the event?
    Last edited by ugluk; 12th September 2011 at 15:24.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractScrollArea scrollbar positions

    What is it exactly that you want to do?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    7
    Qt products
    Qt4

    Default Re: QAbstractScrollArea scrollbar positions

    By default, QAbstractItemView derivatives all erase their backgrounds at every repaint event. But what, if the view is custom and the view's items themselves erase their backgrounds? The view's erase is then superfluous. But if I do:

    Qt Code:
    1. setAttribute(Qt::WA_NoSystemBackground);
    To copy to clipboard, switch view to plain text mode 

    on the view, the backgrounds of the view's scrollbars will not erase. Therefore, I wanted to erase their backgrounds "manually" (via fillRect()), while leaving the view's items to erase their own backgrounds.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractScrollArea scrollbar positions

    Quote Originally Posted by ugluk View Post
    By default, QAbstractItemView derivatives all erase their backgrounds at every repaint event. But what, if the view is custom and the view's items themselves erase their backgrounds?
    What if there are not enough items to cover all the view or some items have transparent background?

    The view's erase is then superfluous. But if I do:

    Qt Code:
    1. setAttribute(Qt::WA_NoSystemBackground);
    To copy to clipboard, switch view to plain text mode 

    on the view, the backgrounds of the view's scrollbars will not erase. Therefore, I wanted to erase their backgrounds "manually" (via fillRect()), while leaving the view's items to erase their own backgrounds.
    Then set the attribute on the view's viewport and not on the view itself. However I don't think this optimalization is worth the effort you are putting into it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Styling QAbstractScrollArea / QListWidget
    By rmwatson in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2010, 23:57
  2. QAbstractScrollArea metrics
    By Olivier Berten in forum Qt Programming
    Replies: 0
    Last Post: 1st February 2010, 08:18
  3. QScrollArea vs. QAbstractScrollArea
    By zaphod.b in forum Qt Programming
    Replies: 15
    Last Post: 7th July 2009, 15:26
  4. QAbstractScrollArea::setViewportMargins() not working :(
    By montylee in forum Qt Programming
    Replies: 7
    Last Post: 21st January 2009, 15:52
  5. QAbstractScrollArea and paintEvent
    By babu198649 in forum Newbie
    Replies: 13
    Last Post: 4th August 2008, 10:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.