Results 1 to 6 of 6

Thread: Problems with QActions and Icons

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Problems with QActions and Icons

    Hi thanx for the reply.
    Here some code that should compile ( in my program ui is built using designer here no )

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. private:
    6. static MainWindow* m_instance;
    7.  
    8. OBox* m_application;
    9. Track* m_track;
    10.  
    11. QModelIndex m_lastPlayedIndex;
    12. QModelIndex m_newIndex;
    13.  
    14. QDateTime m_creationTime;
    15.  
    16. QHash<QDate, QString> m_hash;
    17.  
    18. QLabel *m_progressLabel;
    19. QProgressBar *m_progressBar;
    20.  
    21. QMenu *oboxMenu;
    22. QMenu *vehicleMenu;
    23. QMenu *videoMenu;
    24. QMenu *indexMenu;
    25. QMenu *helpMenu;
    26.  
    27. QAction *exitAction;
    28. QAction *vehicleAddAction;
    29. QAction *vehicleRemoveAction;
    30. QAction *vehicleInfoAction;
    31. QAction *videoSearchAction;
    32. QAction *videoDeleteAction;
    33. QAction *updateIndexAction;
    34. QAction *aboutAction;
    35.  
    36. QToolBar *mainToolBar;
    37.  
    38. private:
    39. void createActions();
    40. void createMenus();
    41. void createToolBar();
    42.  
    43. public:
    44. explicit MainWindow(OBox* application);
    45. static MainWindow* instance();
    46. };
    47.  
    48. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    // The mainwindow ctor ( I removed all non minimal code )
    Qt Code:
    1. MainWindow::MainWindow() : QMainWindow(0)
    2. {
    3. createActions();
    4. createMenus();
    5. createToolBar();
    6. }
    To copy to clipboard, switch view to plain text mode 

    Here I create actions ( only 3 just for test )
    Qt Code:
    1. void MainWindow::createActions()
    2. {
    3. // I create only 3 actions just for test
    4. vehicleAddAction = new QAction(tr("&Add"), this);
    5. vehicleAddAction->setIcon(QIcon(":/Resources/AddVehicle.png"));
    6. vehicleAddAction->setShortcut(QKeySequence::New);
    7. vehicleAddAction->setStatusTip(tr("Add a new vehicle to the list"));
    8. connect(vehicleAddAction, SIGNAL(triggered()), this, SLOT(addVehicle()));
    9.  
    10. vehicleRemoveAction = new QAction(tr("&Remove"), this);
    11. vehicleRemoveAction->setIcon(QIcon(":/Resources/RemoveVehicle.png"));
    12. vehicleRemoveAction->setShortcut(tr("Ctrl+R"));
    13. vehicleRemoveAction->setStatusTip(tr("Remove a vehicle from the list"));
    14. connect(vehicleAddAction, SIGNAL(triggered()), this, SLOT(removeVehicle()));
    15.  
    16. vehicleInfoAction = new QAction(tr("&Info"), this);
    17. vehicleInfoAction->setIcon(QIcon(":/Resources/InfoVehicle.png"));
    18. vehicleInfoAction->setShortcut(tr("Ctrl+I"));
    19. vehicleInfoAction->setStatusTip(tr("Shows info about a vehicle"));
    20. connect(vehicleInfoAction, SIGNAL(triggered()), this, SLOT(infoVehicle()));
    21. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::createMenus()
    2. {
    3. oboxMenu = menuBar()->addMenu(tr("&OBox"));
    4.  
    5. vehicleMenu = menuBar()->addMenu(tr("&Vehicle"));
    6. vehicleMenu->addAction(vehicleAddAction);
    7. vehicleMenu->addAction(vehicleRemoveAction);
    8. vehicleMenu->addSeparator();
    9. vehicleMenu->addAction(vehicleInfoAction);
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::createToolBar()
    2. {
    3. mainToolBar = addToolBar(tr("&OBox"));
    4. mainToolBar->addAction(vehicleAddAction);
    5. mainToolBar->addAction(vehicleRemoveAction);
    6. mainToolBar->addAction(vehicleInfoAction);
    7. }
    To copy to clipboard, switch view to plain text mode 

    I also attach the 3 icons (64x64)

    AddVehicle.pngInfoVehicle.pngRemoveVehicle.png.
    Regards


    Added after 14 minutes:


    Hi anda_skoa,
    which widget should I modify?
    Bye
    Last edited by franco.amato; 14th September 2013 at 15:46.
    Franco Amato

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Problems with QActions and Icons

    Quote Originally Posted by franco.amato View Post
    Hi anda_skoa,
    which widget should I modify?
    Bye
    You don't need to modify any widget to test with a different style. Just set a different style.
    Either by passing a style name to the -style commandline argument or by calling QWidget::setStyle on your main window in main()

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 8th April 2013, 07:40
  2. Shortcuts for QActions...
    By ericV in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2009, 14:18
  3. Problems with Designer for QActions
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2007, 23:10
  4. :( Problems with QTreeWidgetItem icons
    By davit in forum Qt Programming
    Replies: 13
    Last Post: 18th April 2007, 14:38
  5. Problems with QActions and Pixmaps
    By ToddAtWSU in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2007, 22:53

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
  •  
Qt is a trademark of The Qt Company.