Results 1 to 18 of 18

Thread: QTAbBar not displaying

  1. #1
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QTAbBar not displaying

    My QtabBar is not displaying although it is compiling fine and showing the controls.

    Qt Code:
    1. QTab *tab1 = new QTab("General");
    2. qtb.addTab(tab1);
    3. QTab *tab2 = new QTab("About");
    4. qtb.addTab(tab2);
    To copy to clipboard, switch view to plain text mode 
    Last edited by Dune; 7th February 2006 at 16:51. Reason: subscribe

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTAbBar not displaying

    What is the type of that qtb variable? Do you use QTabWidget?

  3. #3
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTAbBar not displaying

    qtb is QTabBar

    I am using QDialog because I thought QTabWidget was for putting widgets in the tabs. Ok controls are called widgets in qt.

  4. #4
    piotrpsz Guest

    Default Re: QTAbBar not displaying

    My example

    Qt Code:
    1. layout->addWidget( d_tab_bar = new QTabBar( parent ));
    2. d_tab_bar->setShape( QTabBar::TriangularBelow );
    3. d_tab_bar->addTab( d_view_tab = new QTab() );
    4. d_tab_bar->addTab( d_console_tab = new QTab() );
    To copy to clipboard, switch view to plain text mode 

    best regards
    piotr

  5. #5
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTAbBar not displaying

    Quote Originally Posted by piotrpsz
    My example

    Qt Code:
    1. layout->addWidget( d_tab_bar = new QTabBar( parent ));
    2. d_tab_bar->setShape( QTabBar::TriangularBelow );
    3. d_tab_bar->addTab( d_view_tab = new QTab() );
    4. d_tab_bar->addTab( d_console_tab = new QTab() );
    To copy to clipboard, switch view to plain text mode 

    best regards
    piotr
    Thanks and I should inherit from QTabWidget?

  6. #6
    piotrpsz Guest

    Default Re: QTAbBar not displaying

    Quote Originally Posted by Dune
    Thanks and I should inherit from QTabWidget?
    No. In my code is all what you need

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTAbBar not displaying

    Quote Originally Posted by piotrpsz
    No. In my code is all what you need
    Does your code require QWidgetStack/QStackedWidget to display tabs?

  8. #8
    piotrpsz Guest

    Default Re: QTAbBar not displaying

    Quote Originally Posted by jacek
    Does your code require QWidgetStack/QStackedWidget to display tabs?
    Full example (with QWidgetStack):

    Qt Code:
    1. void MainWindow::create_work_area( QFrame* const parent )
    2. {
    3. QVBoxLayout* const layout = new QVBoxLayout( parent );
    4. if( layout ) {
    5. layout->addWidget( d_widget_stack = new QWidgetStack( parent ));
    6. layout->addWidget( d_tab_bar = new QTabBar( parent ));
    7.  
    8. d_widget_stack->addWidget( d_workspace = new Workspace( parent ));
    9. d_widget_stack->addWidget( new Console( parent ));
    10.  
    11. d_tab_bar->setShape( QTabBar::TriangularBelow );
    12. d_tab_bar->addTab( d_view_tab = new QTab() );
    13. d_tab_bar->addTab( d_console_tab = new QTab() );
    14.  
    15. connect( d_tab_bar, SIGNAL( selected( int ) ), this, SLOT( set_current_tab( int )));
    16. }
    17. }
    18.  
    19. ...
    20.  
    21. void MainWindow::set_current_tab( int )
    22. {
    23. d_widget_stack->raiseWidget( idx );
    24. d_tab_bar->setCurrentTab( idx );
    25. }
    To copy to clipboard, switch view to plain text mode 

    piotr

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTAbBar not displaying

    Quote Originally Posted by piotrpsz
    Full example (with QWidgetStack):
    [...]
    I see, so in fact you had to implement your own QTabWidget.

  10. #10
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTAbBar not displaying

    Working for me so far. I had to set it up in inheritance mode for me and of course change some formatting to my own. I will see if I can just inherit from the WidgetStack now instaed of using QFrame.

    EDIT:
    Eh, I need the QFrame as a parent.
    Last edited by Dune; 8th February 2006 at 17:18. Reason: No parent

  11. #11
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTAbBar not displaying

    I can't get my labels to change stack position. I would assume when one is raised that it would be on top of the other plus the labels are not changing geometry.

    Qt Code:
    1. TabDialog::TabDialog(QWidget *parent, const char *name, const QString &_filename)
    2. : QFrame(parent, name), filename(_filename), fileinfo(filename)
    3. {
    4. //widget1 = new QWidget(this);
    5. //widget2 = new QWidget(this);
    6. tabbar = new QTabBar(this);
    7.  
    8. tabbar->setShape(QTabBar::RoundedAbove);
    9. tabbar->addTab(viewtab = new QTab("aaaaaaaaaaaaa"));
    10. tabbar->addTab(consoletab = new QTab("dddddddddddd"));
    11.  
    12. widgetstack = new QWidgetStack(this);
    13.  
    14. widgetstack->addWidget(label1= new QLabel("ccccccccccc", this), 1);
    15. widgetstack->addWidget(label2 = new QLabel("ggggggggggg", this), 2);
    16. label1->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    17. label2->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    18.  
    19. connect(tabbar, SIGNAL(selected(1)), this, SLOT(setTab(1)));
    20. connect(tabbar, SIGNAL(selected(2)), this, SLOT(setTab(2)));
    21. //connect( this, SIGNAL( applyButtonPressed() ), this, SLOT( ));
    22. }
    23.  
    24. void TabDialog::setTab(int id)
    25. {
    26. widgetstack->raiseWidget(id);
    27. tabbar->setCurrentTab(id);
    28. resizeEvent(0);
    29. }
    30. // leave this, it's for resizing the frame and then you need sizehints for that
    31. void TabDialog::resizeEvent(QResizeEvent *e)
    32. {
    33. if(e)
    34. QFrame::resizeEvent(e);
    35.  
    36. tabbar->setGeometry(200,0,200,30);
    37. label1->setGeometry(100,50,20,20);
    38. label2->setGeometry(100,100,20,20);
    39. }
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTAbBar not displaying

    Quote Originally Posted by Dune
    connect(tabbar, SIGNAL(selected(1)), this, SLOT(setTab(1)));
    connect(tabbar, SIGNAL(selected(2)), this, SLOT(setTab(2)));
    You can't specify parameter names or values in SLOT and SIGNAL macros.

    Try:
    Qt Code:
    1. connect( tabbar, SIGNAL( selected( int ) ), this, SLOT( setTab( int ) ) );
    To copy to clipboard, switch view to plain text mode 

  13. #13
    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: QTAbBar not displaying

    Quote Originally Posted by Dune
    My QtabBar is not displaying although it is compiling fine and showing the controls.

    Qt Code:
    1. QTab *tab1 = new QTab("General");
    2. qtb.addTab(tab1);
    3. QTab *tab2 = new QTab("About");
    4. qtb.addTab(tab2);
    To copy to clipboard, switch view to plain text mode 
    I think the problem here was you were creating that QTabBar widget on stack and not on heap (based on the way you reference it) and it was being deleted upon return from the function.

  14. #14
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTAbBar not displaying

    Thanks, I redid the code. Seems to be working as the 'aaaa' label disappears when I select a tab but the bbbbb label is hidden and my labels are at 0,0 still.

    Qt Code:
    1. TabDialog::TabDialog(QWidget *parent, const char *name, const QString &_filename)
    2. : QFrame(parent, name), filename(_filename), fileinfo(filename)
    3. {
    4. //widget1 = new QWidget(this);
    5. //widget2 = new QWidget(this);
    6. tabbar = new QTabBar(this);
    7.  
    8. tabbar->setShape(QTabBar::RoundedAbove);
    9. tabbar->addTab(viewtab = new QTab("aaaaaaaaaaaaa"));
    10. tabbar->addTab(consoletab = new QTab("bbbbbbbbbb"));
    11.  
    12. widgetstack = new QWidgetStack(this);
    13.  
    14. widgetstack->addWidget(label1= new QLabel("11111111111", this), 1);
    15. widgetstack->addWidget(label2 = new QLabel("222222222222", this), 2);
    16. label1->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    17. label2->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    18.  
    19. connect(tabbar, SIGNAL(selected(int)), this, SLOT(setTab(int)));
    20. //connect( this, SIGNAL( applyButtonPressed() ), this, SLOT( ));
    21. }
    22.  
    23. void TabDialog::setTab(int idx)
    24. {
    25. if(idx == 1) {
    26. widgetstack->raiseWidget(1);
    27. }
    28. if(idx == 2) {
    29. widgetstack->raiseWidget(2);
    30. }
    31. resizeEvent(0);
    32. }
    33.  
    34. // leave this, it's for resizing the frame and then you need sizehints for that
    35. void TabDialog::resizeEvent(QResizeEvent *e)
    36. {
    37. if(e)
    38. QFrame::resizeEvent(e);
    39. tabbar->setGeometry(200,0,200,30);
    40. label1->setGeometry(100,50,20,20);
    41. label2->setGeometry(100,100,20,20);
    42. }
    To copy to clipboard, switch view to plain text mode 

  15. #15
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTAbBar not displaying

    Quote Originally Posted by wysota
    I think the problem here was you were creating that QTabBar widget on stack and not on heap (based on the way you reference it) and it was being deleted upon return from the function.
    here is my class code:

    Qt Code:
    1. class TabDialog : public QFrame
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. TabDialog( QWidget *parent, const char *name, const QString &_filename );
    7.  
    8. QString filename;
    9. QFileInfo fileinfo;
    10. QWidgetStack widgetstack;
    11. //QWidget *widget1;
    12. //QWidget *widget2;
    13. QTabBar tabbar;
    14. QTab *viewtab;
    15. QTab *consoletab;
    16. QLabel *label1;
    17. QLabel *label2;
    18.  
    19. void resizeEvent(QResizeEvent *e);
    20. protected slots:
    21. void setTab(int idx);
    22.  
    23. // void setupTab2();
    24. // void setupTab3();
    25. };
    To copy to clipboard, switch view to plain text mode 

  16. #16
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTAbBar not displaying

    Ok I am new to pointers. I can only use this '->' with pointers.

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTAbBar not displaying

    Quote Originally Posted by Dune
    Thanks, I redid the code. Seems to be working as the 'aaaa' label disappears when I select a tab but the bbbbb label is hidden and my labels are at 0,0 still.
    Did you set a layout for your dialog? Maybe it will be easier for you to use Qt Designer?

    Qt Code:
    1. if(idx == 1) {
    2. widgetstack->raiseWidget(1);
    3. }
    4. if(idx == 2) {
    5. widgetstack->raiseWidget(2);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Woudn't it be easier to write:
    Qt Code:
    1. widgetstack->raiseWidget( idx );
    To copy to clipboard, switch view to plain text mode 
    ?

  18. #18
    Join Date
    Feb 2006
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTAbBar not displaying

    Thanks and no I dont use that stuff

    I want using a layout but I guess I can.

Similar Threads

  1. Hiding a tab in QTabBar widget
    By erik in forum Qt Programming
    Replies: 9
    Last Post: 12th February 2017, 13:29
  2. Help on QTabBar colors
    By smacchia in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2012, 17:48
  3. Using QTabBar as QTabWidget replacement
    By invictus in forum Qt Programming
    Replies: 0
    Last Post: 16th August 2008, 02:57
  4. Problems with CSS for QTabBar and QTabWidget
    By visor_ua in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2008, 09:38
  5. problems about QTabBar
    By qtopiahooo in forum Qt Programming
    Replies: 4
    Last Post: 10th October 2006, 11:05

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.