Results 1 to 8 of 8

Thread: The action works well, but the action can not use from the setStatusTip()

  1. #1
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default The action works well, but the action can not use from the setStatusTip()

    Hello.in this code, the QMenu and the QAction work well.but the newact can not use from the setStatusTip("Open a new file"); thank you.

    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3. #include <QtWidgets>
    4. class widget:public QMainWindow
    5. {public:
    6. widget();
    7. void createmenu();
    8. void createaction();
    9. private:
    10. QTextEdit*text;
    11. QMenu*filemenu;
    12. QAction*newact;
    13. };
    14. #endif // WIDGET_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include <QtWidgets>
    2. #include "widget.h"
    3. widget::widget()
    4. {text=new QTextEdit;
    5. resize(250,250);
    6. setCentralWidget(text);
    7. createaction();
    8. createmenu();
    9. }
    10. void widget::createmenu()
    11. {filemenu=menuBar()->addMenu(tr("File"));
    12. filemenu->addAction(newact);
    13. }
    14. void widget::createaction()
    15. {
    16. newact=new QAction(tr("&New"),this);
    17. newact->setShortcut(QKeySequence::New);
    18. newact->setStatusTip("Open a new file");
    19. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "widget.h"
    2. #include <QtWidgets>
    3. int main(int argv,char*argc[])
    4. {
    5. QApplication app(argv,argc);
    6. widget window;
    7. window.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The action works well, but the action can not use from the setStatusTip()

    What have you tried so far?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default Re: The action works well, but the action can not use from the setStatusTip()

    I try to display the message on the status bar, when the mouse goes on the new action.But in this code, it does not work.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: The action works well, but the action can not use from the setStatusTip()

    What happen when you derive a class from QMainWindow, but forget to include the Q_OBJECT macro in the class definition? (Look at the header file for any class derived from a Qt QObject class and compare that with the definition of your "widget" class in your header file).

  5. #5
    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: The action works well, but the action can not use from the setStatusTip()

    Quote Originally Posted by rezas1000 View Post
    I try to display the message on the status bar, when the mouse goes on the new action.But in this code, it does not work.
    Can you see a status bar in your window at all?
    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.


  6. #6
    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: The action works well, but the action can not use from the setStatusTip()

    The code as posted does not display a status bar. When you create the status bar it shows the specified text just fine (Linux, Qt 5.3).

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The action works well, but the action can not use from the setStatusTip()

    Quote Originally Posted by rezas1000 View Post
    I try to display the message on the status bar, when the mouse goes on the new action.
    I see no code that indicates that.
    Did you forget to post the code that sets up the status bar?

    Cheers,
    _

  8. #8
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default Re: The action works well, but the action can not use from the setStatusTip()

    I see no code that indicates that.
    Did you forget to post the code that sets up the status bar?
    thank you very much
    The code as posted does not display a status bar. When you create the status bar it shows the specified text just fine (Linux, Qt 5.3).
    thank you very much
    Can you see a status bar in your window at all?
    thank you very much
    What happen when you derive a class from QMainWindow, but forget to include the Q_OBJECT macro in the class definition? (Look at the header file for any class derived from a Qt QObject class and compare that with the definition of your "widget" class in your header file).
    thank you very much


    the code is working well, Because I changed the code and I added the createStatusBar():

    Qt Code:
    1. #include <QtWidgets>
    2. #include "widget.h"
    3. widget::widget()
    4. {text=new QTextEdit;
    5. resize(250,250);
    6. setCentralWidget(text);
    7. createaction();
    8. createmenu();
    9. createStatusBar();
    10. }
    11. void widget::createmenu()
    12. {filemenu=menuBar()->addMenu(tr("File"));
    13. filemenu->addAction(newact);
    14. }
    15. void widget::createaction()
    16. {
    17. newact=new QAction(tr("&New"),this);
    18. newact->setShortcut(QKeySequence::New);
    19. newact->setStatusTip("Open a new file");
    20. }
    21. void widget::createStatusBar()
    22. {
    23. statusBar()->showMessage(tr("Ready"));
    24. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Trapping action from an 'SDI' app
    By blaylockr in forum Newbie
    Replies: 5
    Last Post: 9th July 2008, 20:27
  2. Replies: 3
    Last Post: 1st October 2006, 15:03
  3. pushbutton action
    By mickey in forum Newbie
    Replies: 9
    Last Post: 21st April 2006, 19:46
  4. No action checked in an exclusive action group
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 06:19
  5. action
    By mickey in forum Qt Tools
    Replies: 3
    Last Post: 19th January 2006, 05:18

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.