Results 1 to 3 of 3

Thread: Problem with changing stackedwidget pages by QAction

  1. #1
    Join Date
    May 2009
    Posts
    4
    Thanks
    2

    Default Problem with changing stackedwidget pages by QAction

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem with changing stackedwidget pages by QAction

    Quote Originally Posted by dejvis View Post
    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:
    Qt Code:
    1. // in your *.h
    2. private slots:
    3. void slotPage1();
    4. // in your *.cpp
    5. connect(action1, SIGNAL(triggered()), this, SLOT(slotPage1()));
    6. //...
    7. void MyClass::slotPage1()
    8. {
    9. stackedWidget->setCurrentIndex(0);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 17th May 2009 at 21:36. Reason: add code example

  3. The following user says thank you to Lykurg for this useful post:

    dejvis (17th May 2009)

  4. #3
    Join Date
    May 2009
    Posts
    4
    Thanks
    2

    Default Re: Problem with changing stackedwidget pages by QAction

    That works perfect! thanks!!

Similar Threads

  1. Problem with events changing behavior of QListWidget
    By riklaunim in forum Qt Programming
    Replies: 10
    Last Post: 22nd December 2008, 19:10
  2. Problem to recover an object via a QAction
    By Potch in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2008, 11:19
  3. uic3 QAction problem
    By batileon in forum Qt Programming
    Replies: 0
    Last Post: 16th June 2008, 10:35
  4. problem with Font changing
    By phillip_Qt in forum Qt Programming
    Replies: 22
    Last Post: 25th April 2008, 04:37
  5. QMainWindow: problem changing centralWidget
    By Caius Aérobus in forum Qt Programming
    Replies: 6
    Last Post: 4th October 2007, 13:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.