Results 1 to 9 of 9

Thread: Can Qt open a bottle?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Can Qt open a bottle?

    Hi there,

    i have the frequently annoying question (problem) which probably many have faced before:

    " hide a tab page "

    1) without using removeTab() (because it will be deleted)
    2) without using setTabEnabled() (because with CTRL+TAB one can indeed open it!!!!)
    3) without using QWidgetStack (because it is a part of Qt3)

    is there a solution for this problem? Please notice the nice BUG in point (2). If you would like to care for data integration, this might be a problem or not?

    Qt does all those fascinating things like driving a car but can not open a bottle (or close it if you would prefer)?



    please excuse me for this way of articulation of the problem.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Can Qt open a bottle?

    Quote Originally Posted by sivrisinek View Post
    1) without using removeTab() (because it will be deleted)
    It will not be deleted. You can store a pointer to it and reinsert the tab later on.

    3) without using QWidgetStack (because it is a part of Qt3)
    See QStackedWidget.

  3. #3
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can Qt open a bottle?

    Quote Originally Posted by wysota View Post
    It will not be deleted. You can store a pointer to it and reinsert the tab later on.


    See QStackedWidget.
    What can I do to get the pointer to a specified tabpage? There is not a member method of QTabWidget which returns a QWidget* to the removed page. Or at least I can not find it.

    Here the question is not to hide the whole tab widget; just a single page of it.
    ---

    My Qt Version is 4.2.2, that's why QStackedWidget was documented to belong to Qt3 I guess.

  4. #4
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can Qt open a bottle?

    it is very important for us to hide the page (and not re-instantiate it) as it has much more complex widgets inside and not few buttons and labels..

  5. #5
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    54
    Thanked 2 Times in 2 Posts

    Default Re: Can Qt open a bottle?

    There is not a member method of QTabWidget which returns a QWidget* to the removed page.
    If you know the index of the page to be removed, you might use QTabWidget::widget(int index) to retrieve the tab's pointer before removing it.
    Then you can easily restore it with QTabWidget::addTab(QWidget*,QString) or QTabWidget::insertTab(int,QWidget*,QString).
    I never tested it, but it should work. Shouldn't it?

    EDIT: at the moment is impossible to hide litterally the tab, so this trick seems required. Anyway since you save a pointer to the page, probably its content shall be saved to the restoring too.
    Last edited by Raccoon29; 18th July 2008 at 10:00. Reason: updated contents
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  6. #6
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can Qt open a bottle?

    Quote Originally Posted by Raccoon29 View Post
    If you know the index of the page to be removed, you might use QTabWidget::widget(int index) to retrieve the tab's pointer before removing it.
    Then you can easily restore it with QTabWidget::addTab(QWidget*,QString) or QTabWidget::insertTab(int,QWidget*,QString).
    I never tested it, but it should work. Shouldn't it?

    EDIT: at the moment is impossible to hide litterally the tab, so this trick seems required. Anyway since you save a pointer to the page, probably its content shall be saved to the restoring too.
    Thanks a lot this did really work.

  7. #7
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 8 Times in 8 Posts

    Default Re: Can Qt open a bottle?

    If anyone want an "embeded" solution to this problem, can freely use QExtendedTabWidget

    Have fun.

  8. #8
    Join Date
    Apr 2006
    Location
    Denmark / Norway
    Posts
    67
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    3
    Thanked 12 Times in 8 Posts

    Default Re: Can Qt open a bottle?

    yes, qt can open a bottle if you make a serial port device with a robot arm, program a nice gui with image recognition through a webcam, that finds the bottle and opens it...

    shouldn't take more than a few hours I guess

    For a TabWidget that can add/remove pages, but still remember them, use a stackedwidget where you keep the widgets always, and use a TabBar with indexing, where you update the index when you add/remove tabs.

    I have not tested the below code, as it's a rewrite of something I did a few months ago, but you will get a hint on where to start off.

    header:
    Qt Code:
    1. class MyWidget : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. MyWidget(QWidget *parent);
    6. };
    7.  
    8. class QMyCustomTabBar : public QTabBar
    9. {
    10. Q_OBJECT
    11. public:
    12. QMyCustomTabBar(QWidget *parent);
    13. QList <unsigned short int> TabPage;
    14.  
    15. public slots:
    16. PageToView(int index);
    17. RemoveTabWithNo(unsigned short int stackedpagenumber);
    18. InsertTabWithNo(unsigned short int stackedpagenumber, const QString &TabString);
    19.  
    20. signals:
    21. SendPageToView(unsigned int index);
    22. };
    To copy to clipboard, switch view to plain text mode 
    source:
    Qt Code:
    1. MyWidget::MyWidget(QWidget *parent) : QWidget (parent)
    2. {
    3. QStackedWidget *myStacked = new QStackedWidget(this);
    4. myStacked->addWidget(widget1);
    5. myStacked->addWidget(widget2);
    6. myStacked->addWidget(widget3);
    7.  
    8. QMyCustomTabBar *myCustomTabBar = new QMyCustomTabBar(this);
    9. connect (myCustomTabBar, SIGNAL(SendPageToView(int)), myStacked, SLOT(setCurrentIndex(int)));
    10. // then use RemoveTabWithNo and InsertTabWithNo to remove/insert.
    11. // subclass checkbox'es or add slots for checkbox'es if you need those to enable disable
    12. }
    13.  
    14. QMyCustomTabBar::QMyCustomTabBar(QWidget *parent) : QTabBar (parent)
    15. {
    16. connect (this, SIGNAL(currentChanged(int)), this, SLOT(PageToView(int)));
    17. }
    18.  
    19. void QMyCustomTabBar::PageToView(int index)
    20. {
    21. if (index < this->TabPage.count())
    22. {
    23. emit(SendPageToView(TabPage[index]));
    24. }
    25. }
    26. void QMyCustomTabBar::RemoveTabWithNo(unsigned short int stackedpagenumber)
    27. {
    28. for (int i = 0;i < this->TabPage.count(); i++)
    29. {
    30. if (TabPage[i] == stackedpagenumber)
    31. {
    32. TabPage.removeAt(i);
    33. this->removeTab(i);
    34. return;
    35. }
    36. }
    37. }
    38.  
    39. void QMyCustomTabBar::InsertTabWithNo(unsigned short int stackedpagenumber, const QString &TabString)
    40. {
    41. // see if we have a tab we need to insert it before...
    42. for (int i = 0;i < this->TabPage.count(); i++)
    43. {
    44. if (TabPage[i] > stackedpagenumber)
    45. {
    46. TabPage.insert(i, stackedpagenumber);
    47. this->insertTab(i, TabString);
    48. return;
    49. }
    50. }
    51. // if not, we should insert at the end
    52. this->TabPage.append(stackedpagenumber);
    53. this->addTab(TabString);
    54. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can Qt open a bottle?

    Thanks a lot for the answers.

    Have fun.

Similar Threads

  1. Replies: 3
    Last Post: 7th October 2015, 19:43
  2. Replies: 3
    Last Post: 25th August 2010, 12:39
  3. QTextBrowser: Cannot open
    By veda in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2007, 12:05
  4. again Open Cascade + Qt 4.2.2 but detailed...
    By Shuchi Agrawal in forum Qt Programming
    Replies: 11
    Last Post: 1st February 2007, 07:03
  5. again Open Cascade + Qt 4.2.2 but detailed...
    By Shuchi Agrawal in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 06:50

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
  •  
Qt is a trademark of The Qt Company.