Results 1 to 7 of 7

Thread: hook resizeEvent

  1. #1
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default hook resizeEvent

    Hi,

    I am sub classing QMainWindow and there is a resizeEvent.
    Qt Code:
    1. void resizeEvent(QResizeEvent *e);
    To copy to clipboard, switch view to plain text mode 

    I am also creating some QDockWidgets inside.
    Qt Code:
    1. dock = new QDockWidget(tr("Attributes"), this);
    To copy to clipboard, switch view to plain text mode 

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

    Cheers

    Prashant

  2. #2
    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: hook resizeEvent

    Why do you want to do that? resizeEvent will be called for your widget when it gets resized.
    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.


  3. #3
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hook resizeEvent

    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:
    Qt Code:
    1. this->tabWidget->centerText->resize( this->tabWidget->currentWidget()->size());
    To copy to clipboard, switch view to plain text mode 

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

    Prashant

  4. #4
    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: hook resizeEvent

    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.
    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.


  5. #5
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hook resizeEvent

    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.

    Qt Code:
    1. void myTabWidget::addNewTab(const char *tabName)
    2. {
    3. // Create a new widget
    4. QWidget *newTab = new QWidget(this);
    5. // Add a new tab
    6. this->addTab(newTab, QIcon("../images/win/tabicon.png"), tr(tabName));
    7. // Set size of this widget to size of this
    8. newTab->resize(this->size());
    9. // Make this tab current one.
    10. this->setCurrentIndex(this->count()-1);
    11. // Parent text to this tab.
    12. centerText->setParent(newTab);
    13. // Set size of text equal to size of tab
    14. centerText->resize(newTab->size());
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void myTabWidget::tabChanged(int index)
    2. {
    3. // Reparent text to current widget
    4. centerText->setParent(this->currentWidget());
    5. //Note:
    6. //The widget becomes invisible as part of changing its
    7. //parent, even if it was previously visible. You must
    8. //call show() to make the widget visible again.
    9. centerText->show();
    10. // Set size of text equal to size of tab/widget
    11. centerText->resize(this->currentWidget()->size());
    12. }
    To copy to clipboard, switch view to plain text mode 

    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

  6. #6
    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: hook resizeEvent

    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:
    Qt Code:
    1. void ...::addNewTab(...){
    2. QWidget *newTab = new QWidget;
    3. addTab(newTab, ...);
    4. QVBoxLayout *l = new QVBoxLayout(newTab); // *
    5. centerTab->setParent(newTab);
    6. l->addWidget(centerTab); // *
    7. }
    To copy to clipboard, switch view to plain text mode 

    If you want to have the text edit with the same contents in each tab I would advise to do this instead:
    Qt Code:
    1. void ...::addNewTab(...){
    2. QWidget *newTab = new QWidget;
    3. addTab(newTab, ...);
    4. QVBoxLayout *l = new QVBoxLayout(newTab);
    5. QTextEdit *te = new QTextEdit; // *
    6. te->setDocument(centerTab->document()); // *
    7. l->addWidget(te);
    8. }
    To copy to clipboard, switch view to plain text mode 
    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.


  7. #7
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hook resizeEvent(solved)

    Thanks for the tip. It worked.

    Cheers

    prashant

Similar Threads

  1. What cannot be done in resizeEvent(..)?
    By nifei in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2008, 02:48
  2. QT Keyboard Hook
    By MarcSchubert in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2007, 11:28
  3. resizeEvent from parent to child?
    By ChasW in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2007, 18:21
  4. hook
    By incapacitant in forum Newbie
    Replies: 3
    Last Post: 29th August 2006, 19:53
  5. Question about resizeEvent
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 28th February 2006, 16:13

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.