Results 1 to 6 of 6

Thread: Menu bar not appearing

  1. #1
    Join Date
    Feb 2011
    Posts
    9
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Menu bar not appearing

    Just started using Qt and am wondering why the menu bar doesn't show up, when I run the app. Thank you in advance for helping... Here is the code

    mainwindow.h
    Qt Code:
    1. #ifndef LINES_H
    2. #define LINES_H
    3.  
    4. #include <QWidget>
    5. #include <qmainwindow.h>
    6. #include <QMainWindow>
    7.  
    8. class QMenu;
    9. class QAction;
    10. class QLabel;
    11.  
    12. class Lines : public QMainWindow
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. Lines();
    18.  
    19. private:
    20. void createActions();
    21. void updateActions();
    22. void createMenus();
    23. QMenu *fileMenu;
    24. //QMenu *moveMenu;
    25. QAction *exitAct;
    26.  
    27. protected:
    28. void paintEvent(QPaintEvent *event);
    29. };
    30.  
    31. #endif
    To copy to clipboard, switch view to plain text mode 

    lines.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "mainwindow.h"
    3. #include <QApplication>
    4. #include <QPainter>
    5.  
    6.  
    7. Lines::Lines()
    8. {
    9. createActions();
    10. createMenus();
    11.  
    12. setWindowTitle(tr("Tic Tac Toe"));
    13. resize(270, 270);
    14. }
    15.  
    16. void Lines::paintEvent(QPaintEvent *event)
    17. {
    18. QPen pen(Qt::black, 2, Qt::SolidLine);
    19.  
    20. QPainter painter(this);
    21.  
    22. painter.setPen(pen);
    23. painter.drawLine(93, 20, 93, 250);
    24. painter.drawLine(177, 20, 177, 250);
    25. painter.drawLine(20, 93, 250, 93);
    26. painter.drawLine(20, 177, 250, 177);
    27. //Draw test x
    28. painter.drawLine(30, 30, 80, 80);
    29. painter.drawLine(80, 30, 30, 80);
    30. }
    31.  
    32. void Lines::createActions()
    33. {
    34. exitAct = new QAction(tr("E&xit"), this);
    35. exitAct->setShortcut(tr("Ctrl+Q"));
    36. connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
    37. }
    38.  
    39. void Lines::createMenus()
    40. {
    41. fileMenu = new QMenu(tr("&File"), this);
    42. fileMenu->addAction(exitAct);
    43. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QDesktopWidget>
    3. #include <QApplication>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. Lines Lines;
    9. Lines.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by GUIman; 23rd February 2011 at 00:40.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Menu bar not appearing


  3. The following user says thank you to ChrisW67 for this useful post:

    GUIman (23rd February 2011)

  4. #3
    Join Date
    Feb 2011
    Posts
    9
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Menu bar not appearing

    I am completely new to using the qt framework. could you please explain how I could modify my code to implement your fixes?
    Thank you for putting up with me.

  5. #4
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Menu bar not appearing

    Quote Originally Posted by GUIman View Post
    I am completely new to using the qt framework. could you please explain how I could modify my code to implement your fixes?
    Thank you for putting up with me.
    hi,
    welcome to QtCentre.
    As Chris said, after creating the menus
    Just add ,
    Qt Code:
    1. Lines::Lines()
    2. {
    3. createActions();
    4. createMenus();
    5. menuBar()->addMenu(fileMenu);
    6. ...............
    7. ...............
    8. }
    To copy to clipboard, switch view to plain text mode 
    in class Lines constructor.

    hope it helps.
    Bala

  6. The following user says thank you to BalaQT for this useful post:

    GUIman (23rd February 2011)

  7. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Menu bar not appearing

    I'd put it in createMenus() myself. Seems the logical place for it.

  8. The following user says thank you to ChrisW67 for this useful post:

    GUIman (23rd February 2011)

  9. #6
    Join Date
    Feb 2011
    Posts
    9
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Menu bar not appearing

    Thank you so much
    I got it now!

Similar Threads

  1. scroll bars are not appearing
    By Cruz in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2010, 17:26
  2. Scroll Bar not appearing in QScrollArea
    By coolkaps in forum Newbie
    Replies: 1
    Last Post: 2nd May 2010, 16:12
  3. qwt plugin not appearing in qt3
    By gilbertd26 in forum Qwt
    Replies: 2
    Last Post: 5th January 2009, 10:39
  4. Windows not appearing in XP.
    By beardybloke in forum Qt Programming
    Replies: 7
    Last Post: 24th October 2007, 17:32
  5. A strange set of characters appearing
    By bruccutler in forum Qt Programming
    Replies: 7
    Last Post: 19th April 2007, 16:21

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.