Results 1 to 6 of 6

Thread: QScrollArea?

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

    Question QScrollArea?

    Hi,

    I have a custom widget which I want to place into a QScrollArea, which in turn goes on to a QMainWindow. This is done in a few examples, and I think my code pretty much matches theirs, but I don't seem to get the scroll bars when I resize my window. I am using a QLabel with an image in it for testing. The code in my mainwindow constructor is:
    Qt Code:
    1. label = new QLabel;
    2. QString fileName = QFileDialog::getOpenFileName(this,
    3. tr("Open File"), QDir::currentPath());
    4.  
    5. QImage image(fileName);
    6. label->setPixmap(QPixmap::fromImage(image));
    7.  
    8. scroll = new QScrollArea;
    9. scroll->setWidget(label);
    10.  
    11. setCentralWidget(scroll);
    To copy to clipboard, switch view to plain text mode 

    Any advice or ideas what Im doing wrong?
    The image is displayed on the label, but when I resize the main window to something smaller than the image, no scrollbars appear.. Where am I going wrong? Do I need additional code?

    Thx in advance,
    kw

  2. #2
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Qt products
    Qt3
    Platforms
    Unix/X11
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: QScrollArea?

    hi kw,
    I don't see much wrongs in your code. But try this line instead of line 9 in your code:
    Qt Code:
    1. scroll->addChild(label);
    To copy to clipboard, switch view to plain text mode 
    This would be of some help. But Iam not getting the complete idea of what you want to do.You are saying that you are putting an image in a label.How is that done?
    Regards,
    Sarma.

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows
    Thanks
    9
    Thanked 27 Times in 27 Posts

    Default Re: QScrollArea?

    try this ...
    Qt Code:
    1. scroll->resizeContest(label.width(),label.height());
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  4. #4
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3

    Default Re: QScrollArea?

    Just try with large label size.

    label->resize(1000, 1000);

  5. #5
    Join Date
    Jan 2006
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Wink Re: QScrollArea?

    Phew, found it at last

    A few weird typos there btw guys I think.. QScrollArea doesn't have an addChild member function, and I think setWidget is the way to go.. Since it needs to be linked to a single widget. Maybe the (now deprecated) QScrollView was the one you were thinking of?
    I assume that's also the class that had the resizeContents method (the typo in that made me laugh tho ;-)).. I tried resize() which is present, but that didn't do much
    Resizing the label, like jnana said did have some effect. But it still didn't work/look right.. It showed me what I was doing wrong though.. I was using generated code for the dialog (Im developing in VS with VS Integration), and calling ui.setupUi(this); to create all the required UI parts and connections. The problem was that my code was *before* this GUI setup code, so some parts probably didn't exist yet..
    I put my code *after* the ui.setupUI(this) code, and now it works perfectly.

    -kw

  6. #6
    Join Date
    Jan 2006
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Question Re: QScrollArea?

    I just checked the generated code, and it shows:
    Qt Code:
    1. QWidget *centralWidget;
    2. ...
    3. centralWidget = new QWidget(NforceClass);
    4. centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    5. NforceClass->setCentralWidget(centralWidget);
    To copy to clipboard, switch view to plain text mode 
    Which is presumably what caused all the problems. Now that my own code comes after this, it simply overwrites the centralWidget setting.. But I'm wondering if there isn't some way to remove the centralWidget entirely in that, so that it doesn't get generated anymore? I can see it in my Object Inspector, but that doesn't allow me to do anything with it. I also can't find any scroll area in my Qt Toolbox, so setting a scrollarea as central widget in the form editor is also out of the question I suppose.. It just seems sorta sloppy to have dead code that gets overwritten in the source.
    Any ideas?

    -kw

Similar Threads

  1. Replies: 1
    Last Post: 13th September 2008, 12:00
  2. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2008, 00:45
  3. QScrollArea
    By sabeesh in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2007, 11:33
  4. QScrollArea and resizing
    By rarefluid in forum Qt Programming
    Replies: 8
    Last Post: 22nd July 2007, 15:18
  5. Replies: 2
    Last Post: 8th October 2006, 21:14

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.