Results 1 to 4 of 4

Thread: QAction and setText

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default QAction and setText

    Hi
    I want to add an QAction to toolbar which contains only text(no Icons).The text will contain spaces but the spaces are stripped down even when i used the QAction::setText(const QString& text) function.
    In the following code the space's are stripped downl
    Qt Code:
    1. QAction *ac=new QAction(this);
    2. ac->setText(" act ");//the spaces are stripped down
    3. addToolBar("toolbar")->addAction(ac);
    To copy to clipboard, switch view to plain text mode 

    How to get the spaces in QAction text.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QAction and setText

    Quote Originally Posted by babu198649 View Post
    The text will contain spaces but the spaces are stripped down even when i used the QAction::setText(const QString& text) function.
    Yes, that's intentional.
    J-P Nurmi

  3. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QAction and setText

    The QAction docs says,

    The action uses a stripped version of text (e.g. "&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description with setText().
    How to get the space in the QAction text

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QAction and setText

    Qt Code:
    1. QToolButton* button = new QToolButton(this);
    2. button->setText(" act ");
    3. addToolBar("toolbar")->addWidget(button);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    babu198649 (5th February 2009)

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.