Results 1 to 5 of 5

Thread: Strange performance of QDockWindow?

  1. #1
    Join Date
    Nov 2006
    Posts
    58
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Strange performance of QDockWindow?

    I have a MainWindow subclassed by QMainWindow, and also a QDockWindow on the bottom of the MainWindow. Then I add a QWidgetStack into the QDockWindow. The QWidgetStack contains two QHBox. Each QHBox is a toolbar. Finally, I want to switch on/off between the two toolbar by clicking a toolbutton, that is why I use a QWidgerStack in the QDockWindow.

    However, despite of the swicth on/off functionality, the QDockWindow has a ridiculous presentation or performance, it can not show correctly!

    Below is my code, Please Help Me!

    Qt Code:
    1. #include <qapplication.h>
    2. #include <qstring.h>
    3. #include <qmainwindow.h>
    4. #include <qdockwindow.h>
    5. #include <qtextedit.h>
    6. #include <qtoolbar.h>
    7. #include <qtoolbutton.h>
    8. #include <qpopupmenu.h>
    9. #include <qwidgetstack.h>
    10. #include <qhbox.h>
    11. #include <qlayout.h>
    12.  
    13.  
    14. class MainWindow:public QMainWindow
    15. {
    16. public:
    17. MainWindow(const QString& filename );
    18. QDockWindow *toolBarDockWindow;
    19. QWidgetStack *toolBarStack;
    20. QWidgetStack *mainWindowStack;
    21. QToolButton* fileButton;
    22. QToolButton* editButton;
    23. QToolButton* graphicButton;
    24. QTextEdit *textEdit;
    25.  
    26. private:
    27. void init();
    28. QString m_filename;
    29. };
    30.  
    31. MainWindow::MainWindow(const QString& filename)
    32. :QMainWindow(0,0,WDestructiveClose)
    33. {
    34. int screenW;
    35. int screenH;
    36. screenW = QApplication::desktop()->width();
    37. screenH = QApplication::desktop()->height();
    38. this->resize(screenW,screenH);
    39. m_filename = QString::null;
    40. init();
    41. }
    42.  
    43. void MainWindow::init()
    44. {
    45. toolBarDockWindow = new QDockWindow (QDockWindow::InDock,this,"toolbardockwindow",0);
    46. toolBarDockWindow->setOrientation(Qt::Horizontal);
    47. toolBarDockWindow->setHorizontallyStretchable(TRUE);
    48. toolBarDockWindow->setVerticallyStretchable(TRUE);
    49. toolBarDockWindow->setMovingEnabled(FALSE);
    50. QColor tbBkgColor;
    51. tbBkgColor.setHsv(205,167,189);
    52. toolBarDockWindow->setPaletteBackgroundColor(tbBkgColor);
    53. this->moveDockWindow(toolBarDockWindow,Qt::DockBottom);
    54.  
    55. toolBarStack = new QWidgetStack(toolBarDockWindow);
    56. QHBox* editToolBar = new QHBox(toolBarStack);
    57. editToolBar->setSpacing(6);
    58. editToolBar->setMargin(6);
    59. QHBox* graphicToolBar = new QHBox(toolBarStack);
    60. graphicToolBar->setSpacing(6);
    61. graphicToolBar->setMargin(6);
    62. toolBarStack->addWidget(editToolBar,0);
    63. toolBarStack->addWidget(graphicToolBar,1);
    64.  
    65. fileButton = new QToolButton(editToolBar,"filebutton");
    66. fileButton->setUsesTextLabel(TRUE);
    67. fileButton->setTextLabel("File",FALSE);
    68. fileButton->setFont(QFont("Times",20,QFont::Bold));
    69. fileButton->setPopupDelay(10);
    70.  
    71. QPopupMenu *fileMenu = new QPopupMenu(this);
    72. fileMenu->insertItem("New File",this,SLOT(fileNew()),Qt::Key_F1);
    73. fileMenu->insertItem("Load File",this,SLOT(fileOpen()),Qt::Key_F2);
    74. fileMenu->insertItem("Save File",this,SLOT(fileSave()),Qt::Key_F3);
    75. fileMenu->insertItem("Save File As...",this,SLOT(fileSaveAs()),Qt::Key_F4);
    76. fileButton->setPopup(fileMenu);
    77.  
    78. editButton = new QToolButton(editToolBar,"editbutton");
    79. editButton->setUsesTextLabel(TRUE);
    80. editButton->setTextLabel("Edit",FALSE);
    81. editButton->setFont(QFont("Times",20,QFont::Bold));
    82.  
    83. graphicButton = new QToolButton(editToolBar,"graphicButton");
    84. graphicButton->setUsesTextLabel(TRUE);
    85. graphicButton->setTextLabel("Graphic",FALSE);
    86. graphicButton->setFont(QFont("Times",20,QFont::Bold));
    87.  
    88. QSpacerItem* editToolBarSpacer = new QSpacerItem(0,0 ,QSizePolicy::Expanding,QSizePolicy::Minimum);
    89. editToolBar->layout()->addItem(editToolBarSpacer);
    90.  
    91. toolBarStack->raiseWidget(0);
    92.  
    93. textEdit = new QTextEdit(this,"textedit");
    94. textEdit->setTextFormat(Qt::PlainText);
    95. textEdit->setFocus();
    96. this->setCentralWidget(textEdit);
    97. }
    98.  
    99. int main(int argc, char *argv[])
    100. {
    101. QApplication app(argc,argv);
    102. QString filename = QString::null;
    103. MainWindow *mainWindow = new MainWindow(filename);
    104. app.setMainWidget(mainWindow);
    105. mainWindow->show();
    106.  
    107. return app.exec();
    108. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Strange performance of QDockWindow?

    Wouldn't it be simpler to use regular toolbars? QToolBar inherits QDockWindow so you can use it just like a dock window and you can use show() and hide() to switch between toolbars without a widget stack.

  3. #3
    Join Date
    Nov 2006
    Posts
    58
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Strange performance of QDockWindow?

    Is there any functions like show() or hide() supplied by QToolBar?
    Ok, I will try it.

    But by the way, I have solved the problem by adding this:
    toolBarDockWindow->setWidget(toolBarStack);

    Thanks a lot!

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

    Default Re: Strange performance of QDockWindow?

    Quote Originally Posted by luffy27 View Post
    Is there any functions like show() or hide() supplied by QToolBar?
    Yes, QToolBar inherits QWidget.

    But by the way, I have solved the problem by adding this:
    toolBarDockWindow->setWidget(toolBarStack);
    Using show/hide will give you much cleaner code, especially if you use setShown()/setHidden() which are slots, so that you'll be able to connect them to actions that can trigger those changes.

  5. #5
    Join Date
    Nov 2006
    Posts
    58
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Strange performance of QDockWindow?

    All right, I will try it.
    Thanks a lot!

Similar Threads

  1. Performance problems with overlapping qgraphicsitems
    By brjames in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2008, 21:42
  2. GraphicsView performance problems
    By Gopala Krishna in forum Qt Programming
    Replies: 79
    Last Post: 8th August 2007, 17:32
  3. very strange behaviour
    By regix in forum Qt Programming
    Replies: 23
    Last Post: 20th July 2006, 17:38
  4. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  5. Increasing performance from Qtextedit, listview, etc?
    By taylor34 in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:20

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.