Results 1 to 6 of 6

Thread: Problems with QActions and Icons

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

    Default Problems with QActions and Icons

    Hi to all,
    I'm writing an application where I have a MainWindow. I added a Menu Bar and QActions.
    The problem is that the icons and the text in the menu are overlapped on the left side of menu
    like in the images I'm attaching.

    Here some code:

    in mainwindow.h
    Qt Code:
    1. class MainWindow : public QMainWindow, private Ui::MainWindow
    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. // .... more code
    44. }
    To copy to clipboard, switch view to plain text mode 

    and in mainwindow.cpp

    Qt Code:
    1. void MainWindow::createActions()
    2. {
    3. exitAction = new QAction(tr("&Exit"), this);
    4. //exitAction->setIcon(QIcon(":/Resources/exit.png"));
    5. exitAction->setShortcut(tr("Ctrl+Q"));
    6. exitAction->setStatusTip(tr("Exit the application"));
    7. connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
    8.  
    9. vehicleAddAction = new QAction(tr("&Add"), this);
    10. vehicleAddAction->setIcon(QIcon(":/Resources/AddVehicle.png"));
    11. vehicleAddAction->setShortcut(QKeySequence::New);
    12. vehicleAddAction->setStatusTip(tr("Add a new vehicle to the list"));
    13. connect(vehicleAddAction, SIGNAL(triggered()), this, SLOT(addVehicle()));
    14. // .... more code
    15. }
    16.  
    17. void MainWindow::createMenus()
    18. {
    19. oboxMenu = menuBar()->addMenu(tr("&OBox"));
    20. oboxMenu->addAction(exitAction);
    21.  
    22. vehicleMenu = menuBar()->addMenu(tr("&Vehicle"));
    23. vehicleMenu->addAction(vehicleAddAction);
    24. vehicleMenu->addAction(vehicleRemoveAction);
    25. vehicleMenu->addSeparator();
    26. vehicleMenu->addAction(vehicleInfoAction);
    27. // .... more code
    28. }
    To copy to clipboard, switch view to plain text mode 
    I call the functions in the ctor of MainWindow class.
    I'm attaching a screenshot. What I'm doing wrong?
    Is not the first time I do something similar but is the first time that I get a similar result.

    I hope to get some help.

    Regards,
    FrancoMenuError.jpg
    Franco Amato

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

    Default Re: Problems with QActions and Icons

    More than 50 visits and 0 replies....maybe I posted a foo question?
    Franco Amato

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems with QActions and Icons

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Problems with QActions and Icons

    Also try running with a different widget style, just to check that it is not the style that is at fault.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    franco.amato (14th September 2013)

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

    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 14:46.
    Franco Amato

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

    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, 06:40
  2. Shortcuts for QActions...
    By ericV in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2009, 13:18
  3. Problems with Designer for QActions
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2007, 22:10
  4. :( Problems with QTreeWidgetItem icons
    By davit in forum Qt Programming
    Replies: 13
    Last Post: 18th April 2007, 13:38
  5. Problems with QActions and Pixmaps
    By ToddAtWSU in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2007, 21: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.