Results 1 to 14 of 14

Thread: Adding a scrollbar to a QWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Adding a scrollbar to a QWidget

    Hold on... the code above suggests you don't know how to use layouts. Is that true? Can you show us the definition of your tag cloud widget?
    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.


  2. #2
    Join Date
    Feb 2009
    Posts
    45
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows
    Thanks
    3

    Default Re: Adding a scrollbar to a QWidget

    Quote Originally Posted by wysota View Post
    Hold on... the code above suggests you don't know how to use layouts. Is that true?
    Well, yes I am learning, and have been looking at different forum threads and QT documentation to understand why it is not working in my application, and if I am getting the order wrong or missing out on calling cetain settings.
    So, yes, I am not 100% comfortable in the way the layouts work, but am eager to learn the right approach.

    Quote Originally Posted by wysota View Post
    Can you show us the definition of your tag cloud widget?
    I have put snippets of what my code looks like hence it might not be complete.
    The mainWidget inherits from another user-defined class (which has some customised functions ) and this in turn inherits from QWidget

    ie. mainWidget--> myCustomisedClass->QWidget

    Thank you once again for your patience.

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

    Default Re: Adding a scrollbar to a QWidget

    I don't care what it is derived from. I only care if it has a proper layout or not. Please provide the full unmodified contents of the constructor.
    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.


  4. #4
    Join Date
    Feb 2009
    Posts
    45
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows
    Thanks
    3

    Default Re: Adding a scrollbar to a QWidget

    There is no layout specified in the constructor.

    I tried implementing layouts in the ui, and have enclosed them (both ui's: before and after my changes)

    - To give you additional information of this Window. It has an option of either viewing words as a list (QListWidget) or as a tag cloud (QWidget)
    Before
    - In the UI file, there is only the QlistWidget added , there is no layout present. (attachment: tagCloud-before.ui)
    - But when the application runs for the listWidget the scrollbar appears when needed.
    - the tag cloud widget is added at runtime.

    After
    - I made modifications to the ui file (tagCloud-after.ui), by enclosing the QListWidget in a ScrollArea.
    - I put them in a grid-layout, as when I tried other layouts the QListWidget was not expanding as the window is resized.
    Question: Is this the correct layout to use? If not, if you have just one widget in a scrollArea, which is the preferred layout?
    - at runtime I tried to hookup the tagcloud to the scrollArea

    Qt Code:
    1. Ui::TagCloud ui_tagCloud;
    2. ui_tagCloud.scrollAreaWords->setWidget(tagCloudDisplay);
    To copy to clipboard, switch view to plain text mode 
    The application starts to run but hangs after awhile.

    Is this a good approach?
    Attached Files Attached Files

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

    Default Re: Adding a scrollbar to a QWidget

    The one "after" is better. But still, I was asking about your tag cloud (tagCloudDisplay) and not the scroll area window.
    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.


  6. #6
    Join Date
    Feb 2009
    Posts
    45
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows
    Thanks
    3

    Default Re: Adding a scrollbar to a QWidget

    Thanks Wyosta.

    In reply to your questions:
    - tagCloudDisplay is a member variable.
    - Details are as follows

    Class 1 : MyApplication
    Qt Code:
    1. void MyApplication::createTagWindow()
    2. {
    3. TagWindowWidget* tagWindow = new TagWindowWidget; // This class inherits from a customised class which in turn inherits from QObject
    4. Ui::TagCloud ui_TagCloud; // This is the ui attached
    5. ui_tagCloud.setupUi(tagWindow );
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 
    Class 2: WordsManager (inherits directly from QObject)
    Qt Code:
    1. void WordsManager::loadWordWindow( QWidget *tagCloud, QListWidget *wordList)
    2. {
    3.  
    4. WordsDisplay *wordsDisplayWindow = new WordsDisplay(tagCloud, wordList)
    5. }
    To copy to clipboard, switch view to plain text mode 

    The WordsDisplay class structure is as follows:

    Qt Code:
    1. class WordsDisplay : public QObject
    2. {
    3.  
    4. Q_OBJECT
    5.  
    6. protected:
    7. QWidget* tagCloudDisplay;
    8. QListWidget* wordListDisplay;
    9. :
    10. :
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    - I am trying to associate the 'scrollArea' in the ui to the tagCloudDisplay. Would this be the solution?
    - How can I do this with the structure I have? As I am not able to retrieve the ui.scrollArea after the tagCloudDisplay is instantiated

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

    Default Re: Adding a scrollbar to a QWidget

    We're not getting anywhere...

    I'm asking you to present your code because I want to have a look at it, not because I want to steal something from you. If you want me to help you, you have to provide the code I ask you for, not the one you feel like sharing at the moment.

    I need to know how the tag cloud is composed. It probably doesn't have a layout applied and I'm pretty certain you didn't reimplement sizeHint() for your widget. Therefore the widget has no real size and will not make the scroll area have scrollbars ever.

    Furthermore please read this: Using a Designer .ui File in Your Application - please follow one of the recommended approaches.
    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. QGraphicsView and adding QWidget with transparent areas
    By sting73 in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2009, 11:19
  2. Replies: 11
    Last Post: 25th February 2009, 17:35
  3. Replies: 0
    Last Post: 11th November 2008, 15:36
  4. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  5. GraphicsView/GraphicsScene: scrollbar policy Qt::ScrollBarAsNeeded
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2007, 13:15

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.