Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: setText in QToolButton ( qt4 )

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default setText in QToolButton ( qt4 )

    Hi,

    I have a QToolButton which is having a "QPixmap" loading from resourcefile ( MyResourceFile.qrc ) , with Qt3Support.

    After setting setting pixmap , am setting text in QToolButton uisng setText(). But in GUI it is not showing the TEXT , instead displays only the QOixmap.

    see the code..
    Qt Code:
    1. MyMainWindow::MyMainWindow()
    2. {
    3. --------
    4. ---------
    5.  
    6. QToolButton *btn= new QToolButton( QIcon(":Images/imageOne.png"), tr("Quit"),
    7. tr("Quit"), this, SLOT( close() ), myToolBar, "Quit"); //setting pixmap in QToolButton
    8.  
    9. btn->setText("My Text......"); //setting text in QToolButton
    10.  
    11.  
    12. ---------
    13. ---------
    14. -------
    15. }
    To copy to clipboard, switch view to plain text mode 


    Why this is not showing the text in QToolButton...??????
    please help me
    Last edited by jacek; 3rd July 2007 at 20:39. Reason: wrapped too long line

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setText in QToolButton ( qt4 )

    Try this :

    Qt Code:
    1. btn->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
    To copy to clipboard, switch view to plain text mode 

    By default, a QToolButton is in IconMode only, and won't display text

  3. #3
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: setText in QToolButton ( qt4 )

    It is not working...

  4. #4
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setText in QToolButton ( qt4 )

    Well then, post some more code, so I can reproduce the problem.

  5. #5
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: setText in QToolButton ( qt4 )

    I have given the full code in the first thread.
    let me explain...
    In my mainwindow-constructor i have created a QToolButton. that's it.

    You can try the same in your code.
    But the only difference is i am porting the code from Qt3.3.4 to Qt 4.2.2 using the QT3Support.

    please help me.
    thank you.

  6. #6
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setText in QToolButton ( qt4 )

    Ok, I'll try this in a small example once I'm at work (in 20 minutes) ;-)

  7. #7
    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: setText in QToolButton ( qt4 )

    Could you provide a minimal and compilable example reproducing the problem? QToolButton::setToolButtonStyle() works just fine for me when using plain QToolButtons and QToolBar::setToolButtonStyle() does the trick when adding QActions to a QToolBar.
    J-P Nurmi

  8. #8
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setText in QToolButton ( qt4 )

    EDIT :
    Ooops sorry, forget what I wrote

    I'm almost finished with my sample.

  9. #9
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setText in QToolButton ( qt4 )

    By the way, if you don't set any pixmap in the button, does the string become visible ?

    I've made a little sample code, showing string only, and it works here...here it goes in attachment.
    Attached Files Attached Files

  10. #10
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: setText in QToolButton ( qt4 )

    Quote Originally Posted by guilugi View Post
    By the way, if you don't set any pixmap in the button, does the string become visible ?
    Thanks for your attempt.
    I can use either ICON or TEXT. But i need a button which can accomedate ICON & TEXT.

    N:B : Here am giving the full code. i am using Q3ToolBar and adding QToolButton to it. see this

    Qt Code:
    1. MyMainWindow::MyMainWindow()
    2. {
    3.  
    4. --------
    5. ---------
    6. Q3ToolBar *myToolBar = new Q3ToolBar( this );
    7.  
    8. QToolButton *btn= new QToolButton( QIcon(":Images/imageOne.png"), tr("Quit"),
    9. tr("Quit"), this, SLOT( close() ), myToolBar, "Quit"); //setting pixmap in QToolButton
    10.  
    11.  
    12.  
    13. btn->setText("My Text......"); //setting text in QToolButton
    14.  
    15.  
    16.  
    17.  
    18.  
    19. ---------
    20.  
    21. ---------
    22.  
    23. -------
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    Now can you identify....??
    Can i set any property so that i can accomedate both the icon , text. ...????



    thank u

  11. #11
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setText in QToolButton ( qt4 )

    Why can't you just use QToolBar, the native Qt4 class ?

  12. #12
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setText in QToolButton ( qt4 )

    Okay okay,

    I compiled an example similar to yours, using Q3ToolBar, Q3MainWindow.
    and yes, text doesn't appear at all.

    I'll try to investigate further...but it may be an issue of Qt3support.
    You should really switch to Qt4 native code, it's easy to use ;-)

  13. #13
    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: setText in QToolButton ( qt4 )

    This is why we asked for full compilable code, to see the big picture. We had no way to know which Qt3Support classes were used and how. Anyway, you must use Q3MainWindow::setUsesTextLabel(true):
    Qt Code:
    1. setUsesTextLabel(true);
    2. Q3ToolBar *myToolBar = new Q3ToolBar( this );
    3. QToolButton *btn= new QToolButton(...);
    4. btn->setText(...);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  14. #14
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setText in QToolButton ( qt4 )

    Great !
    Works fine for me too

  15. #15
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: setText in QToolButton ( qt4 )

    Quote Originally Posted by jpn View Post
    Anyway, you must use Q3MainWindow::setUsesTextLabel(true):
    Qt Code:
    1. setUsesTextLabel(true);
    2. Q3ToolBar *myToolBar = new Q3ToolBar( this );
    3. QToolButton *btn= new QToolButton(...);
    4. btn->setText(...);
    To copy to clipboard, switch view to plain text mode 

    Thank you.
    The above code what you have given is working perfectly.
    But by seting Q3MainWindow::setUsesTextLabel(true) , all the QToolButton is showing it's TEXT. That is not i want.


    I need to setText() along with ICON ,in a particular Q3ToolBar in MyMainWindow.
    Otherwise can i set this Text+ICON feature to a particular QToolButton...???

    Is there any way to do that.??

    Thank u.

  16. #16
    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: setText in QToolButton ( qt4 )

    Quote Originally Posted by joseph View Post
    I need to setText() along with ICON ,in a particular Q3ToolBar in MyMainWindow.
    Otherwise can i set this Text+ICON feature to a particular QToolButton...???

    Is there any way to do that.??
    I'm afraid this is not possible with Q3MainWindow + Q3ToolBar (see Q3ToolBar::event() for full explanation). I suggest you forget Qt3Support classes and port to native Qt 4 widgets. With QToolBar this is possible by adding individual QToolButtons via QToolBar::addWidget().
    J-P Nurmi

  17. #17
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: setText in QToolButton ( qt4 )

    I have tried this code below .. using QToolBar ,QToolButton.
    But the toolButton ( ie; QUIT ) seems to come on the file menu ,it's hiding the Main menus of MyMainWindow..

    Qt Code:
    1. MyMainWindow::MyMainWindow
    2. {
    3. debugToolBar = new QToolBar( this );
    4. Q_CHECK_PTR( debugToolBar );
    5. debugToolBar->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
    6. debugToolBar->setAllowedAreas( Qt::TopToolBarArea );
    7.  
    8.  
    9. QToolButton *debugButton0 = new QToolButton( QIcon( " :icons/resources/image.png "), tr("Quit"),
    10. tr("Quit"), this, SLOT( close() ),debugToolBar, "Quit");
    11. debugButton0->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
    12. debugButton0->setText("Quit....");
    13. debugToolBar->addWidget( debugButton0 );
    14.  
    15.  
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 
    see the image of MyMainWindow in attachment
    Attached Files Attached Files

  18. #18
    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: setText in QToolButton ( qt4 )

    What happens if you construct the button like this?
    Qt Code:
    1. QToolButton *debugButton0 = new QToolButton(debugToolBar);
    2. debugButton0->setIcon(QIcon(":icons/resources/image.png"));
    3. debugButton0->setText("Quit....");
    4. debugButton0->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
    5. connect(debugButton0, SIGNAL(clicked()), this, SLOT(close()));
    6. debugToolBar->addWidget( debugButton0 );
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  19. #19
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: setText in QToolButton ( qt4 )

    Quote Originally Posted by jpn View Post
    What happens if you construct the button like this?
    Qt Code:
    1. QToolButton *debugButton0 = new QToolButton(debugToolBar);
    2. debugButton0->setIcon(QIcon(":icons/resources/image.png"));
    3. debugButton0->setText("Quit....");
    4. debugButton0->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
    5. connect(debugButton0, SIGNAL(clicked()), this, SLOT(close()));
    6. debugToolBar->addWidget( debugButton0 );
    To copy to clipboard, switch view to plain text mode 
    jpn , i have tried the same code what you did But the QToolButton is coming on the file menu
    .Please see the snapshot of my mainwindow attachmented in the above thread.

    thank u

  20. #20
    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: setText in QToolButton ( qt4 )

    Do you add the toolbar to mainwindow?
    J-P Nurmi

Similar Threads

  1. QToolButton text alignment
    By Vladimir in forum Qt Programming
    Replies: 6
    Last Post: 2nd March 2007, 07:42
  2. QSqlRelationalDelegate Draw a clickable QToolButton
    By patrik08 in forum Qt Programming
    Replies: 5
    Last Post: 1st March 2007, 20:59
  3. Replies: 1
    Last Post: 26th November 2006, 09:32
  4. Problem with qtoolbutton
    By moowy in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2006, 13:30
  5. Need help with QToolButton
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2006, 14:55

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.