This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[Solved] Toggle QDockWidget

Tags: None
(comma "," separated)
Spomky
Registered Member
Posts
15
Karma
0
OS

[Solved] Toggle QDockWidget

Mon Jul 27, 2009 5:43 pm
Hi,

I have a QDockWidget I want to hide/show with an action in the menu bar.

My code :
Code: Select all
QAction* dockInformations = this->dockinfo->toggleViewAction();
dockInformations->setText(i18nc("@dockwidget informations","Informations"));
dockInformations->setIcon(KIcon("mail-task"));
actionCollection()->addAction("dockInformations", dockInformations);


My apps.rc :
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<gui name="fusible" version="1">
   <MenuBar>
      ...
      <Menu name="settings" >
         <Action name="dockInformations" />
      </Menu>
   </MenuBar>
   <ToolBar name="mainToolBar" >
      ...
   </ToolBar>
</gui>


When I compile and execute, there is no action in my menu and I have the following warning :
Code: Select all
Attempt to use QAction "dockInformations" with KXMLGUIFactory!


But this action is available in the toolbar actions collection, I can add it in the main toolbar.

Where is my error?

Last edited by Spomky on Sat Aug 01, 2009 3:00 pm, edited 1 time in total.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Toggle QDockWidget

Tue Jul 28, 2009 5:30 am
You need to use the KAction class in KDE applications, as QActions should not be used. This is because QActions cannot be used in the shortcut dialog.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Spomky
Registered Member
Posts
15
Karma
0
OS

Re: Toggle QDockWidget

Tue Jul 28, 2009 9:59 pm
Thanks but how can I convert a QAction* to KAction*? There is no constructor or function for that.
When I write:
Code: Select all
QAction* dockInformations = (KAction*)this->dockinfo->toggleViewAction();

I have the same problem.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Toggle QDockWidget

Wed Jul 29, 2009 7:01 am
You will need to manually construct a KAction which has the appropriate icon, text, and slot connections and that to the collection manually.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Spomky
Registered Member
Posts
15
Karma
0
OS

Re: Toggle QDockWidget

Wed Jul 29, 2009 6:44 pm
Thank you, it works correctly.
I hoped to use toggleViewAction but it does not matter.
Final code is:
Code: Select all
   KAction* dockInformations = actionCollection()->addAction("show_dock_informations");
   dockInformations->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_I));
   dockInformations->setText(i18n("Informations"));
   dockInformations->setIcon(KIcon("mail-task"));
   dockInformations->setCheckable(true);
   dockInformations->setChecked(this->dockinfo->isVisible());
   connect(dockInformations,SIGNAL(toggled(bool)), this->dockinfo, SLOT(setVisible(bool)));


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]