Results 1 to 9 of 9

Thread: how to remove tab with closable button.

  1. #1
    Join Date
    Sep 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default how to remove tab with closable button.

    so i have a QTabWidget and i want the tabs to be removable via the provided close button for each tab. how do i set it up so that 1) they will close when i click it and 2) i can delete what they where storing becuase i dynamically allocated there page widgits.

  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: how to remove tab with closable button.



    Next time, please at least take a look at the docs before asking a question.
    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 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to remove tab with closable button.

    i looked this time just didn't find it, i think i can remember to look 20min after you told me to in another thread

  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: how to remove tab with closable button.

    So next time browse the docs two times before asking a question
    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 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to remove tab with closable button.

    i still dont understand how implement these functions to work, how do i add checks for things to the "event loop" exactly?

    would i use a function like this?
    Qt Code:
    1. MainWindow::eventFilter(QObject* obj, QEvent event) {
    2. if(obj==this) {
    3. for(unsigned int i=0;i<Tabs->size();++i) {
    4. if(tabCloseRequested(i)) {
    5. delete Tabs->widget(i)->deleteLater();
    6. Tabs->removeTab(i);
    7. }
    8. }
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ishkabible; 20th September 2010 at 01:34.

  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: how to remove tab with closable button.

    Quote Originally Posted by ishkabible View Post
    i still dont understand how implement these functions to work,
    The signal tells you which tab requested to be closed. Connect a slot to it and remove the tab in question.

    how do i add checks for things to the "event loop" exactly?
    What checks and what things?
    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 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to remove tab with closable button.

    ok i'm pretty confused, i thought that i had to add a function to check for a signal to emitted in the event to the event loop, i am guessing this is done with slots but i don't know how to use slots. i use the QObject::connect function to connect a signal and a slot right?, could you explain how this is done and what two objects should be connected for this to be acomplised?

  8. #8
    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: how to remove tab with closable button.

    Quote Originally Posted by ishkabible View Post
    i use the QObject::connect function to connect a signal and a slot right?
    Yes.
    could you explain how this is done and what two objects should be connected for this to be acomplised?
    You have to create your own slot compatible with the signal I gave you and connect() the two. The slot will receive the index of the tab that wishes to be closed and you will just have to remove and delete it.

    If that's still not clear enough (and even if it is) you should read about signals and slots in the docs.
    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.


  9. The following user says thank you to wysota for this useful post:

    ishkabible (20th September 2010)

  10. #9
    Join Date
    Sep 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default

    ok so i tried(did not try to handle memory leeks)
    Qt Code:
    1. QObject::connect(Tabs, SIGNAL(tabCloseRequested(int)),
    2. Tabs, SLOT(removeTab(int)));
    To copy to clipboard, switch view to plain text mode 
    i thought that if this worked then i would make a function in my MainWindow class that would both delete the content and remove the tab but this did not work, what am i doing wrong?

    i got it to work!! i used a function that deleted the allocated widgit with deleteLater, i used

    Qt Code:
    1. QObject::connect(Tabs, SIGNAL(tabCloseRequested(int)),
    2. this, SLOT(RemoveTab(int)));
    To copy to clipboard, switch view to plain text mode 
    , thanks for helping
    Last edited by wysota; 20th September 2010 at 07:40.

Similar Threads

  1. Remove max,min button on a QMainWindow
    By Krish_ng in forum Qt Programming
    Replies: 9
    Last Post: 3rd August 2012, 13:36
  2. Closable dockwidgets
    By Kal in forum Qt Programming
    Replies: 0
    Last Post: 24th October 2008, 21:32
  3. Remove close button on a Dialog in Linux
    By Krish_ng in forum Qt Programming
    Replies: 5
    Last Post: 20th July 2007, 07:10
  4. Remove restore button
    By vermarajeev in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2007, 13:29
  5. Replies: 6
    Last Post: 21st February 2007, 20:35

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.