1 Attachment(s)
ScrollArea in a tabWidget
Hello there :)
Here's my problem: I've got this application: Attachment 9945
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:
Code:
//here's the constructor
scrollArea
= new QScrollArea(this);
//i've created a QScrollArea* in my .h scrollArea->setWidgetResizable(true);
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
Re: ScrollArea in a tabWidget
I am not sure I understand the problem, but why not add the scrolll area in designer?
Cheers,
_
2 Attachment(s)
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: Attachment 9946
with my code: Attachment 9947
Re: ScrollArea in a tabWidget
Sounds like your tab is missing the layout. Check that you have a layout assigned to the tab.
Cheers,
_
1 Attachment(s)
Re: ScrollArea in a tabWidget
There's one (I think). Here's a screenshot of my QtDesigner for my QTabWidget (named "Onglets")Attachment 9948
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,
_
2 Attachment(s)
Re: ScrollArea in a tabWidget
I've done what you told me but it's still not working. Here's what I have: Attachment 9949Attachment 9950.
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...
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,
_
Re: ScrollArea in a tabWidget
I've done what you told me but the scrollbars are not showing up. My code:
Code:
//my constructor
container
= new QWidget();
//the empty widget ui.scrollArea->setWidget(container); //that I add to my scrollArea
//this my text Edit's creation
txt
= new QTextEdit(container
);
//I create my textEdit and set its parent to the created widget connect(txt->document(), SIGNAL(contentsChanged()), this, SLOT(update_size()));
txt->installEventFilter(this);
txt
->setFont
(QFont("Times New Roman", fontSize
));
txt->setTextColor(fontColor);
txt->show();
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,
_
Re: ScrollArea in a tabWidget
How do you suggest that I do that? I tried that but still not working:
Code:
ui.scrollArea->setWidget(container);
container->setLayout(layout);
ui.scrollArea->setWidgetResizable(true);
1 Attachment(s)
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.
Attachment 9952
Cheers,
_
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.
Re: ScrollArea in a tabWidget
The designer ui file is attached, the Form.ui is a link.
Cheers,
_
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?
Code:
//my .h file
//my .cpp file
//Constructor
ui.scrollArea->setWidget(container);
container->setLayout(layout);
ui.scrollArea->setLayout(layout);
ui.scrollArea->setWidgetResizable(true);
//Slot which creates my textEdits
txt->setParent(container);
connect(txt->document(), SIGNAL(contentsChanged()), this, SLOT(update_size()));
txt->installEventFilter(this);
txt
->setFont
(QFont("Times New Roman", fontSize
));
txt->setTextColor(fontColor);
txt->show();
Re: ScrollArea in a tabWidget
You are missing the layout->addWidget(txt) call.
Cheers,
_
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 :)