[Kommander-devel] Re: Mainwindow proxy - again
Eric Laffoon
eric at kdewebdev.org
Thu Mar 27 00:09:48 EDT 2008
On Wednesday 26 March 2008 2:09:17 pm Sebastian Sauer wrote:
> Eric Laffoon wrote:
> > On Wednesday 26 March 2008 7:12:40 pm Eric Laffoon wrote:
> >> On Wednesday 26 March 2008 4:03:07 pm Eric Laffoon wrote:
> >> > On Wednesday 26 March 2008 3:41:17 pm Eric Laffoon wrote:
> >> > > Keven's last suggestion...
> >> >
> >> > bool QtActionProxy::actionIsOn(const QString& action)
> >> > {
> >> > QWidget* mainWindow = kapp->mainWidget();
> >> > if (mainWindow == 0) return false; // no main widget
> >> > QAction* childAction =
> >> > dynamic_cast<QAction*>(mainWindow->child(action.utf8 (), "QAction"));
> >> > if (childAction == 0) return false;
> >> >
> >> > return childAction->isOn();
> >> > }
> >> >
> >> > replacing the first line with
> >> > QWidget* mainWindow = QWidget::topLevelWidget();
> >> > works! I realize it the code no longer tests for whether it's a
> >> > mainwindow now but the point is I can now see how to do it. I still
> >> > find it confusing... so I may have more questions, but I can at least
> >> > see one working function.
> >> >
> >> > Thanks all!
> >>
> >> Actions work perfectly. However the string used to get them is not for
> >> the faint of heart. Consequently I'm not finding an easy solution to get
> >> access to the statusBar. I'm hoping toolbars are easier. Menus are a
> >> plus. Any help?
>
> I am not sure there if I got it right, but e.g. the statusbar is a child of
> the mainwindow. So, if the statusbar has the objectName "mystatusbar" (
> mystatusbar->setObjectName("mystatusbar") with Qt4, with Qt3 it was iirc
> something like mystatusbar->setName("mystatusbar") ), then you should be
> able to access it with something like
> QStatusbar *sb = mainWindow->findChildren<QStatusbar>("mystatusbar");
> (that's again Qt4-syntax ;)
> Since there should be only one statusbar, you may also be able to fetch the
> statusbar without the objectname;
> QStatusbar *sb = mainWindow->findChildren<QStatusbar>();
It sounded good. Here's what else didn't work ;)
void QtActionProxy::mwstatusbar(const QString& action, int param)
{
//QWidget* mainWindow = QWidget::topLevelWidget();
//QStatusbar *sb = mainWindow->findChildren<QStatusbar>();
// QStatusBar *sb =
dynamic_cast<QStatusBar*>(mainWindow->find<QStatusBar>());
//QStatusBar* statbar= QMainWindow::statusBar() const;
// QStatusBar* statbar =
dynamic_cast<QStatusBar*>(mainWindow->child(statusBar(), "QStatusBar"));
//QWidget* sb = mainWindow.find ( "automatic status bar" )->message( action,
param );
//QObject* sb = mainWindow.child("automatic status bar", QStatusBar, TRUE);
QObject* mainWindow = QWidget::topLevelWidget();
QObject* sb mainWindow::child ( "automatic status bar");
sb->message( action, param );
}
--
Eric Laffoon
Project Lead - kdewebdev module
More information about the Kommander-devel
mailing list