[Qt-interest] Creating Gedit like buttons

Ferenc Stelcz ferenc at stelcz.hu
Wed Apr 15 13:38:48 CEST 2009


Ferenc Stelcz wrote:
> Raja Sekharan wrote:
[...]
>> 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);
>>

One additional comment I have probably overseen:
"this->setToolButtonStyle()" is this correct?

*this* points to a QMainWindow instance as you said, so calling 
setToolButtonStyle() on it may not produce the desired effect if you're 
not placing your buttons on a QToolBar. (At least the docs don't mention 
anything about it)
Have you tried to rewrite it like 
this->newbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon) ?

But to be sure, I still advise you to use QToolBar and set its movable 
property to false.



More information about the Qt-interest-old mailing list