Results 1 to 10 of 10

Thread: Adding scroll bars to a main window

  1. #1
    Join Date
    Dec 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Adding scroll bars to a main window

    I want to add H and V scroll bars to my application which only has a QMainWindow. I can't seem to find a property for it and if I try to add a QScrollArea to either the mainwindow or the centralwidget it doesn't seem to work. I've looked through Assistant and through The Book of Qt 4 by Daniel Molkentin but haven't been able to figure it out.

    Thanks
    Doug

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding scroll bars to a main window

    The scroll bar will appear automagically when QScrollArea contents becomes to big.

  3. #3
    Join Date
    Dec 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding scroll bars to a main window

    Isn't working for me.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Adding scroll bars to a main window

    May we see some code? How do you construct the scroll area and its contents? Is the scroll area in a layout or as central widget?
    J-P Nurmi

  5. #5
    Join Date
    Dec 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding scroll bars to a main window

    In the constructor of the main window I have the following code:

    setupUi(this)
    QScrollArea* scrollArea = new QScrollArea;
    scrollArea->setWidget(mw);

    mw is a pointer to this instance of the main window; the window will display but without scroll bars. If I use setWidget(this) (which I would think would be the correct way to do it) the window never shows up at all. If I do setWidget(centralwidget) I just get a blank window.

    Thanks
    Doug

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding scroll bars to a main window

    You should set the QScrollArea as the central widget for your main window and add the contents of the main window to the scroll area.

  7. #7
    Join Date
    Dec 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding scroll bars to a main window

    And how do I do that?

  8. #8
    Join Date
    Dec 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding scroll bars to a main window

    Or I guess to make the "How do I do that?" question clearer - I'm using Designer to create the window and in it's ui_xxx.h file it is creating its own central widget - how do I over-ride that with my own central widget without having to edit the ui header?

    Thanks
    Doug

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding scroll bars to a main window

    Well, at some point you either have to subclass the UI class or include it in your own class. You can use setCentralWidget to override the central widget sometime before your window is first shown.

    Be careful not to delete the previous central widget. The main window will do that.

  10. #10
    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: Adding scroll bars to a main window

    If you want your main window to contain a scroll area with something inside, an option might be to promote a QFrame to QScrollArea in Designer, put the contents you want inside the promoted frame and call QScrollArea::setWidget on the contents of the promoted frame inside the widget constructor, right after calling setupUi().

Similar Threads

  1. minimizing main window
    By eric in forum Qt Programming
    Replies: 4
    Last Post: 28th November 2007, 17:54
  2. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 16:40
  3. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 14:27
  4. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 11:21
  5. Main window
    By Michiel in forum Qt Tools
    Replies: 1
    Last Post: 21st March 2006, 00:54

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.