Results 1 to 17 of 17

Thread: ScrollArea in a tabWidget

  1. #1

    Question ScrollArea in a tabWidget

    Hello there
    Here's my problem: I've got this application: aze.jpg
    My left widget is a TabWidget in which I can add some textEdits. Those textEdit adapt their size to the content they have (they grow bigger each time you write something in them). My problem is the tab widget I got is far too small and I would like to be able to scroll it when my textEdit becomes to big to be fully displayed in it.

    I've tried to create a QScrollArea but the scrollbars are not showing up:
    Qt Code:
    1. //here's the constructor
    2. scrollArea = new QScrollArea(this); //i've created a QScrollArea* in my .h
    3. scrollArea->setWidgetResizable(true);
    4. ui.Onglets->insertTab(0, scrollArea, "Kayaaa");//i try to add my scrollArea to my tabWidget but it creates a new tab and I would like the scrollArea to be in my existing tabs
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: ScrollArea in a tabWidget

    I am not sure I understand the problem, but why not add the scrolll area in designer?

    Cheers,
    _

  3. #3

    Default Re: ScrollArea in a tabWidget

    I've tried to do it on Designer but it doesn't work. My problem is: I add some textEdits which have my qtabWidget as "parent". Those textEdit grow bigger each time you add text in them (so that you always see the full text). But when they are bigger than the qtabwidget (they need to be because the user needs to have plenty of space to be able to write a lot of things) I would like my QTabWidget to display a vertical scrollbar so that the user can see what he has been writing.
    My problem with designer is that the scrollArea is that it doesn't take my qtabWidget size (it's not taking the entire tabs and it doesn't display the scrollbars).
    My problem with my code is that I've got to create a new Tab to make the scrollArea take the entire size of my tab and it's not working. On top of that I'd like my background to be white and not grey as it is when I compile. Here's a screenshot of what I have:

    with designer: reza.jpg
    with my code: aze.jpg
    Last edited by Yaoming; 18th January 2014 at 18:37.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea in a tabWidget

    Sounds like your tab is missing the layout. Check that you have a layout assigned to the tab.

    Cheers,
    _

  5. #5

    Default Re: ScrollArea in a tabWidget

    There's one (I think). Here's a screenshot of my QtDesigner for my QTabWidget (named "Onglets")eaz.PNG

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea in a tabWidget

    Indeed. Since it is a QGridLayout the problem could be that the scroll area is not spanning across all columns. This can be a bit tricky in designer but is doable with a bit of experiementation.

    However, now that the "main" widget of the tab should be the scroll area, maybe you can reduce the number of spacers, e.g. just one horizontal and one vertical to keep the button in the top right corner.
    This should make it easier to place the scroll area.

    Cheers,
    _

  7. #7

    Default Re: ScrollArea in a tabWidget

    I've done what you told me but it's still not working. Here's what I have: art.jpgqsd.jpg.
    I don't know how to have just one scrollbar that would be shown whenever my current tab content is bigger than the tab's size. I could use a QVerticalScrollBar perhaps? That might be harder I don't know...

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

    Default Re: ScrollArea in a tabWidget

    This looks like the text edit being a cild of the tab instead of being inside the scrollarea.

    Since you want more than one widget inside the scrollarea, add a normal and empty QWidget into it, see QScrollArea::setWidget()
    Then add your text edits to that widget, using whatever layout you find appropriate.

    Cheers,
    _

  9. #9

    Default Re: ScrollArea in a tabWidget

    I've done what you told me but the scrollbars are not showing up. My code:
    Qt Code:
    1. //my constructor
    2. container = new QWidget(); //the empty widget
    3. ui.scrollArea->setWidget(container); //that I add to my scrollArea
    4. //this my text Edit's creation
    5. txt = new QTextEdit(container); //I create my textEdit and set its parent to the created widget
    6. connect(txt->document(), SIGNAL(contentsChanged()), this, SLOT(update_size()));
    7. txt->installEventFilter(this);
    8. txt->setFont(QFont("Times New Roman", fontSize));
    9. txt->setTextColor(fontColor);
    10. txt->show();
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea in a tabWidget

    The container does not have a layout. So if the size of the text edit increases it does not increase the size of the container.

    Cheers,
    _

  11. #11

    Default Re: ScrollArea in a tabWidget

    How do you suggest that I do that? I tried that but still not working:
    Qt Code:
    1. container = new QWidget();
    2. layout = new QVBoxLayout();
    3. ui.scrollArea->setWidget(container);
    4. container->setLayout(layout);
    5. ui.scrollArea->setWidgetResizable(true);
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea in a tabWidget

    Yes, like that.

    I just did a quick experiement in designer and I get scroll bars when the scroll area is smaller than the text edits inside it.
    Form.ui

    Cheers,
    _

  13. #13

    Default Re: ScrollArea in a tabWidget

    Could you please give me your code? Because what I have is not working... I've tried different ways but in vain.
    Last edited by Yaoming; 20th January 2014 at 13:33.

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea in a tabWidget

    The designer ui file is attached, the Form.ui is a link.

    Cheers,
    _

  15. #15

    Default Re: ScrollArea in a tabWidget

    Ok but you did it with Designer. In my case, I can't... Here's all my code for this part, do you see any mistakes? Would you have done it differently?
    Qt Code:
    1. //my .h file
    2. QVBoxLayout* layout;
    3. QTextEdit* txt;
    4. QWidget* container;
    5.  
    6. //my .cpp file
    7. //Constructor
    8. container = new QWidget();
    9. layout = new QVBoxLayout();
    10. ui.scrollArea->setWidget(container);
    11. container->setLayout(layout);
    12. ui.scrollArea->setLayout(layout);
    13. ui.scrollArea->setWidgetResizable(true);
    14.  
    15. //Slot which creates my textEdits
    16. txt = new QTextEdit();
    17. txt->setParent(container);
    18. connect(txt->document(), SIGNAL(contentsChanged()), this, SLOT(update_size()));
    19. txt->installEventFilter(this);
    20. txt->setFont(QFont("Times New Roman", fontSize));
    21. txt->setTextColor(fontColor);
    22. txt->show();
    To copy to clipboard, switch view to plain text mode 

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ScrollArea in a tabWidget

    You are missing the layout->addWidget(txt) call.

    Cheers,
    _

  17. #17

    Default Re: ScrollArea in a tabWidget

    Still not working... Anyway you've helped me a lot so I'm going to try and figure it out by myself and stop bothering you.
    Thanks for your help

Similar Threads

  1. Help me about QGridLayout and ScrollArea
    By homerux in forum Newbie
    Replies: 3
    Last Post: 12th August 2013, 01:11
  2. scrollArea
    By skizzik in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2011, 13:55
  3. ItemViews in ScrollArea
    By SElsner in forum Newbie
    Replies: 3
    Last Post: 5th June 2010, 00:59
  4. Autoscroll in ScrollArea
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2009, 06:37
  5. QTreeWidget without the ScrollArea?
    By Paalrammer in forum Newbie
    Replies: 5
    Last Post: 13th February 2007, 20:06

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.