PDA

View Full Version : setText in QToolButton ( qt4 )



joseph
3rd July 2007, 15:27
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..


MyMainWindow::MyMainWindow()
{
--------
---------

QToolButton *btn= new QToolButton( QIcon(":Images/imageOne.png"), tr("Quit"),
tr("Quit"), this, SLOT( close() ), myToolBar, "Quit"); //setting pixmap in QToolButton

btn->setText("My Text......"); //setting text in QToolButton


---------
---------
-------
}



Why this is not showing the text in QToolButton...??????
please help me

guilugi
3rd July 2007, 15:50
Try this :



btn->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );


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

joseph
4th July 2007, 06:51
It is not working...

guilugi
4th July 2007, 06:53
Well then, post some more code, so I can reproduce the problem.

joseph
4th July 2007, 07:12
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.

guilugi
4th July 2007, 07:49
Ok, I'll try this in a small example once I'm at work (in 20 minutes) ;-)

jpn
4th July 2007, 07:54
Could you provide a minimal and compilable example reproducing the problem? QToolButton::setToolButtonStyle() (http://doc.trolltech.com/4.3/qtoolbutton.html#toolButtonStyle-prop) works just fine for me when using plain QToolButtons and QToolBar::setToolButtonStyle() (http://doc.trolltech.com/4.3/qtoolbar.html#toolButtonStyle-prop) does the trick when adding QActions to a QToolBar.

guilugi
4th July 2007, 08:17
EDIT :
Ooops sorry, forget what I wrote :)

I'm almost finished with my sample.

guilugi
4th July 2007, 08:26
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.

joseph
4th July 2007, 08:34
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



MyMainWindow::MyMainWindow()
{

--------
---------
Q3ToolBar *myToolBar = new Q3ToolBar( this );

QToolButton *btn= new QToolButton( QIcon(":Images/imageOne.png"), tr("Quit"),
tr("Quit"), this, SLOT( close() ), myToolBar, "Quit"); //setting pixmap in QToolButton



btn->setText("My Text......"); //setting text in QToolButton





---------

---------

-------

}


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



thank u

guilugi
4th July 2007, 08:40
Why can't you just use QToolBar, the native Qt4 class ?

guilugi
4th July 2007, 08:52
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 ;-)

jpn
4th July 2007, 08:58
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):


setUsesTextLabel(true);
Q3ToolBar *myToolBar = new Q3ToolBar( this );
QToolButton *btn= new QToolButton(...);
btn->setText(...);

guilugi
4th July 2007, 09:01
Great !
Works fine for me too :)

joseph
4th July 2007, 09:34
Anyway, you must use Q3MainWindow::setUsesTextLabel(true):


setUsesTextLabel(true);
Q3ToolBar *myToolBar = new Q3ToolBar( this );
QToolButton *btn= new QToolButton(...);
btn->setText(...);




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.

jpn
4th July 2007, 09:45
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(). ;)

joseph
4th July 2007, 12:45
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..



MyMainWindow::MyMainWindow
{
debugToolBar = new QToolBar( this );
Q_CHECK_PTR( debugToolBar );
debugToolBar->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
debugToolBar->setAllowedAreas( Qt::TopToolBarArea );


QToolButton *debugButton0 = new QToolButton( QIcon( " :icons/resources/image.png "), tr("Quit"),
tr("Quit"), this, SLOT( close() ),debugToolBar, "Quit");
debugButton0->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
debugButton0->setText("Quit....");
debugToolBar->addWidget( debugButton0 );



}

see the image of MyMainWindow in attachment

jpn
4th July 2007, 13:12
What happens if you construct the button like this?


QToolButton *debugButton0 = new QToolButton(debugToolBar);
debugButton0->setIcon(QIcon(":icons/resources/image.png"));
debugButton0->setText("Quit....");
debugButton0->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
connect(debugButton0, SIGNAL(clicked()), this, SLOT(close()));
debugToolBar->addWidget( debugButton0 );

joseph
5th July 2007, 06:24
What happens if you construct the button like this?


QToolButton *debugButton0 = new QToolButton(debugToolBar);
debugButton0->setIcon(QIcon(":icons/resources/image.png"));
debugButton0->setText("Quit....");
debugButton0->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
connect(debugButton0, SIGNAL(clicked()), this, SLOT(close()));
debugToolBar->addWidget( debugButton0 );



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

jpn
5th July 2007, 07:38
Do you add the toolbar to mainwindow?

joseph
5th July 2007, 09:59
Do you add the toolbar to mainwindow?

Actually am porting from Qt3 to Qt4. So in my application "MyMainWindow" is a Q3MainWindow and QToolBar( qt4 ) , QToolButton( qt4 ).

So i think i have to change Qt3 -MainWindow to Qt4-MainWindow... right ..?

Is there any other way...??

guilugi
5th July 2007, 10:05
No, I don't think there's an alternative.

Your application will work much better with Qt4 MainWindow though :)
And porting your code to Qt4 won't be that hard, except if it's really big!

jpn
5th July 2007, 10:06
So i think i have to change Qt3 -MainWindow to Qt4-MainWindow... right ..?
Yes, that's right. Unfortunately you cannot mix them up in this case.

joseph
5th July 2007, 10:26
Thank you jpn.

I am planning to change the Q3MainWindow to QMainwindow (qt4) ,but later.
Now i will go with the QPushButtons( Not looks good in Toolbar).