Results 1 to 9 of 9

Thread: Qscrollarea does not scroll

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qscrollarea does not scroll

    I'm trying to use scrollarea, but I don't get scrollbars.

    In my constructor I have
    Qt Code:
    1. ui->setupUi(this);
    2. Canvas = new JCanvas;
    3. ui->scrollArea->setWidget(Canvas);
    4. Canvas->setGeometry(0, 0, 0, 0);
    To copy to clipboard, switch view to plain text mode 
    where JCanvas is my implementation of QLabel.

    Next, I load a picture and then
    Qt Code:
    1. QPixmap _image;
    2. _image.load(_fileName);
    3. _image = _image.scaledToWidth(_getSize.PictureWidth);
    4. Canvas->setPixmap(&_image);
    5. //...
    6. qDebug()<<ui->scrollArea->geometry();
    7. qDebug()<<_image.size();
    To copy to clipboard, switch view to plain text mode 

    in the output for example I got
    QRect(11,47 1498x1262)
    QSize(1500, 1220)
    so size of the pictura is bigger than my qscrollarea.

    Here is a screenshot
    zrzut ekranu1.jpg

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qscrollarea does not scroll

    Since your scroll area is defined in an ui-file: Are you sure, you set the right scroll bar policies? (See verticalScrollBarPolicy and horizontalScrollBarPolicy)

  3. #3
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qscrollarea does not scroll

    I set ScrollBarAsNeeded in both

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

    Default Re: Qscrollarea does not scroll

    What does your Canvas implementation look like? Does it have a layout? If not, did you reimplement sizeHint()?
    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
    Sep 2010
    Location
    Poland
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qscrollarea does not scroll

    no and no...

    part of JCanvas.h

    Qt Code:
    1. class JCanvas : public QLabel
    2. {
    3. public:
    4. JCanvas();
    5. void paintEvent(QPaintEvent *);
    6. bool ShowHelpingLines;
    7. void setPixmap(QPixmap *p);
    8. void mouseMoveEvent(QMouseEvent *ev);
    9. void mousePressEvent(QMouseEvent *ev);
    10. void setLabels(QLabel *labelX, QLabel *labelY);
    11.  
    12. QStringList cutImages(QString dir);
    13.  
    14. helpingLines HelpingLines;
    15. QVector<JSquare> Squares;
    16. void clearSquares();
    17.  
    18. private:
    19. QPen Pen;
    20. QPen PenCut;
    21. int MouseX, MouseY;
    22. QPixmap Pixmap;
    23. QLabel *LabelX, *LabelY;
    24. };
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Qscrollarea does not scroll

    You need to implement sizeHint() properly for your widget to inform its environment about its preferred/required size. QLabel already does that but if you change its behaviour it is likely to return wrong values for what you are doing.
    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.


  7. #7
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qscrollarea does not scroll

    thanks.

    Unfortunately, I don't know how the implementation should look like...

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

    Default Re: Qscrollarea does not scroll

    You are the only one who may know it. Only you know what it does and how it does it. We don't.
    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.


  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qscrollarea does not scroll

    At a guess your size hint should be the same as the size of the image you load into the JCanvas. Implement QWidget::sizeHint() in your JCanvas and return that size as a starting point. You may also want to try setting QSizePolicy::Fixed on the JCanvas.

Similar Threads

  1. QScrollArea and scroll
    By uKCuH in forum Newbie
    Replies: 1
    Last Post: 1st July 2010, 12:22
  2. Scroll Bar not appearing in QScrollArea
    By coolkaps in forum Newbie
    Replies: 1
    Last Post: 2nd May 2010, 16:12
  3. Force a Scroll in a QScrollArea
    By nmuntz in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2009, 13:49
  4. Auto scroll down in QScrollArea
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2008, 12:51
  5. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 13:27

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
  •  
Qt is a trademark of The Qt Company.