[Qt-interest] Creating Gedit like buttons

Ferenc Stelcz ferenc at stelcz.hu
Wed Apr 15 08:01:17 CEST 2009


Raja Sekharan wrote:
> I've tried QToolButton with setting setToolButtonStyle to
> Qt::ToolButtonTextUnderIcon but, now the button text label isn't
> displaying.
> 
> The code I've used is below:
> 
> Here newbutton is a toolbutton and 'this' is a qmainwindow. tlayout is
> the layout of the widget that acts as the toolbar. 
> 
> this->newbutton->setIcon(QIcon(":/new.png"));
> this->newbutton->setToolTip(QString("Create A New Entry (Ctrl + N)"));
> this->newbutton->setFixedSize(100,100);
> this->newbutton->setText("New Entry");
> this->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
> 
> tlayout->addWidget(this->newbutton);
> 
> I am not using a qtoolbar because the toolbar should not be movable.
> Instead I use a QWidget with QHBoxLayout in which I am adding the
> button. Could this be the issue why the text is not displaying?
> 
> Raj

Is the button associated with some QAction? (It looks like for me) If 
yes, create a new QAction, set its icon, text, tooltip, etc. then 
associate this action with your toolbutton (via setDefaultAction()), 
then set your toolbutton's style to as what I've already written. HTH

BTW. you _can_ make a QToolBar that doesn't allow to be moved. See the 
QToolBar docs and look for the `floatable` and `movable` properties. 
Once set a toolbar, add your buttons and call setToolButtonStyle on it, 
so all toolbuttons on it will have the same style (-> code less :)




More information about the Qt-interest-old mailing list