PDA

View Full Version : hook resizeEvent



prashant
5th September 2009, 18:35
Hi,

I am sub classing QMainWindow and there is a resizeEvent.


void resizeEvent(QResizeEvent *e);


I am also creating some QDockWidgets inside.


dock = new QDockWidget(tr("Attributes"), this);


How do I setup resizeEvent for dock so that it calls this->resizeEvent.

Cheers

Prashant

wysota
6th September 2009, 10:17
Why do you want to do that? resizeEvent will be called for your widget when it gets resized.

prashant
6th September 2009, 13:00
The central widget is a tabWidget, where each tab contains a textedit. When I resize the docks at left, right or bottom, textedit doesn't resize as expected.

When resizing the window(maximize, minimize, stretch) , things are working fine, as I am
adjusting the size of textedit:


this->tabWidget->centerText->resize( this->tabWidget->currentWidget()->size());


May be I am doing wrong and there is another way of doing this correctly.

Prashant

wysota
6th September 2009, 13:27
Calling a resizeEvent will not make anything resize. It is an event that informs a widget it has (already) been resized. Your problem seems to be that you didn't apply a layout to some of the widgets in the tab widget.

prashant
6th September 2009, 14:00
Ok,

Here are some details:

1. I am sub classing tabWidget.
2. There is only one textEdit widget.
3. When ever you create a new tab, you reparent the textEdit to the newly created tab.
4. when you delete a tab, you reparent the textEdit to the current tab.



void myTabWidget::addNewTab(const char *tabName)
{
// Create a new widget
QWidget *newTab = new QWidget(this);
// Add a new tab
this->addTab(newTab, QIcon("../images/win/tabicon.png"), tr(tabName));
// Set size of this widget to size of this
newTab->resize(this->size());
// Make this tab current one.
this->setCurrentIndex(this->count()-1);
// Parent text to this tab.
centerText->setParent(newTab);
// Set size of text equal to size of tab
centerText->resize(newTab->size());

}




void myTabWidget::tabChanged(int index)
{
// Reparent text to current widget
centerText->setParent(this->currentWidget());
//Note:
//The widget becomes invisible as part of changing its
//parent, even if it was previously visible. You must
//call show() to make the widget visible again.
centerText->show();
// Set size of text equal to size of tab/widget
centerText->resize(this->currentWidget()->size());
}


This tab widget is centerWidget and there are docks (left, right and bottom) to it.
When you resize the main window or you resize the dock the textedit should cover the
whole tab area.

Prashant

wysota
6th September 2009, 17:49
As I said, you're not applying layouts to the tabs. Furthermore it looks like you're trying to reuse the same widget for multiple tabs which doesn't make much sense... Anyway:

void ...::addNewTab(...){
QWidget *newTab = new QWidget;
addTab(newTab, ...);
QVBoxLayout *l = new QVBoxLayout(newTab); // *
centerTab->setParent(newTab);
l->addWidget(centerTab); // *
}

If you want to have the text edit with the same contents in each tab I would advise to do this instead:

void ...::addNewTab(...){
QWidget *newTab = new QWidget;
addTab(newTab, ...);
QVBoxLayout *l = new QVBoxLayout(newTab);
QTextEdit *te = new QTextEdit; // *
te->setDocument(centerTab->document()); // *
l->addWidget(te);
}

prashant
7th September 2009, 12:35
Thanks for the tip. It worked.

Cheers

prashant