PDA

View Full Version : Problem with changing stackedwidget pages by QAction



dejvis
17th May 2009, 20:49
Hello

so i'am lil newbie and just started learning

I made main window with QStackedWidget, there is QTreeView and QColumnView inside it.

I managed to make QComboBox to swtich betwen pages (treeview and columnview) but i want to have 2 QActions in menubar: first to enable treeview, second to enable columnview.

How to write connection betwen QAction and QStackedWidget to switch pages?

thanks and sorry for meh eng :)

Lykurg
17th May 2009, 21:31
i want to have 2 QActions in menubar: first to enable treeview, second to enable columnview.

How to write connection betwen QAction and QStackedWidget to switch pages?

A direct connection is not possible. Just create two private slots and connect the correspondent action to it. The slot - normal member function - changes the page. (<- you have to do that.)

If you only want to use one slot look a QSignalMapper.

Edit:

// in your *.h
private slots:
void slotPage1();
// in your *.cpp
connect(action1, SIGNAL(triggered()), this, SLOT(slotPage1()));
//...
void MyClass::slotPage1()
{
stackedWidget->setCurrentIndex(0);
}

dejvis
17th May 2009, 21:58
That works perfect! thanks!!