You are not logged in.

1

Wednesday, April 28th 2004, 8:30am

Adding buttons to toolbar

Hi to all, i need a litle help.
I develope my first application with kdevelop wizard (Application Framework).
Only need know how to add buttons in setupActions function for custom menu entries.

This is my setupActions()

KStdAction::undo(this, SLOT(undo()), actionCollection());
KStdAction::redo(this, SLOT(redo()), actionCollection());

//my menu
QIconSet m_Icon = QIconSet(BarIcon("data_visualization_section"), QIconSet::Small);

(void)new KAction(i18n("New &User"), 0, this, SLOT(newUser()),actionCollection(), "newUser");

(void) new KAction(i18n("&Save User"), m_Icon, 0, this,SLOT(saveUser()), actionCollection(), "saveUser");

I need add two buttons to the standard toolbar, one for de "New User" and other for "Save User"

Anyone can tell me how to do this ?

excuse my broken English
Best Regards from Spain

e8johan

Beginner

Posts: 27

Location: Sweden

  • Send private message

2

Wednesday, April 28th 2004, 8:35am

RE: Adding buttons to toolbar

Look here: http://www.derkarl.org/kdedocs/classKAction.html

This is what you are looking for:

Quoted

That just inserted the action into the File menu. The point is, it's not important in which menu it is: all manipulation of the item is done through the newAct object.

newAct->plug(toolBar());

3

Wednesday, April 28th 2004, 9:03am

RE: Adding buttons to toolbar

Thanks but i dont understand this.

The code only work ok if y write my code before the createGUI call, if i write my code after not work. Is this normal ??

Work ok:

createGUI("/danny/programacion/kviewimage/src/kviewimageui.rc");
KAction *newAct = new KAction(i18n("&New"), "filenew",
KStdAccel::shortcut(KStdAccel::New),
this, SLOT(fileNew()),
actionCollection(), "new");
QPopupMenu *file = new QPopupMenu;
newAct->plug(file);
newAct->plug(toolBar());

not work:

KAction *newAct = new KAction(i18n("&New"), "filenew",
KStdAccel::shortcut(KStdAccel::New),
this, SLOT(fileNew()),
actionCollection(), "new");
QPopupMenu *file = new QPopupMenu;
newAct->plug(file);
newAct->plug(toolBar());

createGUI("/danny/programacion/kviewimage/src/kviewimageui.rc");
Best Regards from Spain

RaD

Unregistered

4

Wednesday, April 28th 2004, 12:26pm

About toolbar and rc file

You're right about kviewimageui.rc file.

But it would be better if you leave createGUI brackets empty:
createGUI();

When you make 'make install' as root, this rc file will be installed properly in system and createGUI() will take it (see more info at KMainWindow::createGUI).

Format of rc file:

<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="kisilox" version="1">
<MenuBar>
<Menu name="menuTasks">
<text>Tasks</text>
<Action name="create_task" />
<Separator />
<Action name="process_task" />
<Action name="process_all_tasks" />
</menu>
</MenuBar>
<!-- This is a comment //-->
<ToolBar name="Tasks"
fullWidth="false"
newline="false"
iconText="icononly" <!-- textonly, icontext[right|bottom] //-->
position="top" <!-- left, right, bottom //-->
hidden="false"
noEdit="false">
<text>Tools</text>
<Action name="create_task" />
<Action name="process_task" />
<Action name="process_all_tasks" />
</ToolBar>
</kpartgui>

When you create an action:

KAction *create_task = new KAction(i18n("Create Task"), 0,
m_view, SLOT(cmenuCreateTask()),
actionCollection(), "create_task");

it's name has to match with action name within rc file (see actions there).

I hope it helps. Sorry my poor english.

5

Thursday, April 29th 2004, 4:06am

Yes it's help me, thanks for the info
Best Regards from Spain