Results 1 to 3 of 3

Thread: Custom widget in QScrollArea

  1. #1
    Join Date
    Jan 2016
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Custom widget in QScrollArea

    Hi,

    i create a widget in a QScrollArea that should fill the entire widget with red color, but when i scroll to the right, i see that it's not filled completely. The frame is drawn correctly. Here is my code:

    Qt Code:
    1. #include <QMainWindow>
    2. #include <QPainter>
    3. #include <QScrollArea>
    4.  
    5. class MyWidget : public QWidget
    6. {
    7. public:
    8.  
    9. virtual void paintEvent(QPaintEvent* e)
    10. {
    11. QPainter painter(this);
    12. painter.fillRect(geometry(), Qt::red);
    13. }
    14. };
    15.  
    16. class ScrollTest : public QMainWindow
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. ScrollTest(QWidget *parent = 0) : QMainWindow(parent)
    22. {
    23. setGeometry(QRect(100,100,230,230));
    24.  
    25. MyWidget* widget = new MyWidget;
    26. widget->setGeometry(QRect(0,0, 250, 250));
    27. widget->setStyleSheet("border: 3px solid blue;");
    28.  
    29. QScrollArea* area = new QScrollArea(this);
    30. area->setGeometry(QRect(0,0, 200, 200));
    31. area->setWidget(widget);
    32. }
    33. };
    To copy to clipboard, switch view to plain text mode 


    This is a simple test dialog. The real widget is an image viewer/editor. I tried QLabel to draw the image, but this is very slow when you zoom in with large images. What i want to do is to zoom and scroll through the image.

    What's wrong?
    Attached Images Attached Images
    Last edited by ElRudi; 14th January 2016 at 13:28.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget in QScrollArea

    Have you tried filling (0, 0, width, height)?

    Maybe geometry() has negative x/y

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget in QScrollArea

    That's it! Thank you!

Similar Threads

  1. Replies: 6
    Last Post: 13th August 2011, 19:31
  2. Replies: 0
    Last Post: 11th August 2010, 11:02
  3. QScrollArea With Custom Widgets
    By VireX in forum Qt Programming
    Replies: 30
    Last Post: 22nd April 2007, 17:48
  4. QScrollArea display custom QLabel
    By spawnwj in forum Qt Programming
    Replies: 6
    Last Post: 6th December 2006, 04:38
  5. size issues for custom QWidget in QScrollArea
    By anotheruser in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2006, 15:52

Tags for this Thread

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.