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
class MainWindow
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
private:
static MainWindow* m_instance;
OBox* m_application;
Track* m_track;
QHash<QDate, QString> m_hash;
private:
void createActions();
void createMenus();
void createToolBar();
// .... more code
}
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
private:
static MainWindow* m_instance;
OBox* m_application;
Track* m_track;
QModelIndex m_lastPlayedIndex;
QModelIndex m_newIndex;
QDateTime m_creationTime;
QHash<QDate, QString> m_hash;
QLabel *m_progressLabel;
QProgressBar *m_progressBar;
QMenu *oboxMenu;
QMenu *vehicleMenu;
QMenu *videoMenu;
QMenu *indexMenu;
QMenu *helpMenu;
QAction *exitAction;
QAction *vehicleAddAction;
QAction *vehicleRemoveAction;
QAction *vehicleInfoAction;
QAction *videoSearchAction;
QAction *videoDeleteAction;
QAction *updateIndexAction;
QAction *aboutAction;
QToolBar *mainToolBar;
private:
void createActions();
void createMenus();
void createToolBar();
// .... more code
}
To copy to clipboard, switch view to plain text mode
and in mainwindow.cpp
void MainWindow::createActions()
{
exitAction
= new QAction(tr
("&Exit"),
this);
//exitAction->setIcon(QIcon(":/Resources/exit.png"));
exitAction->setShortcut(tr("Ctrl+Q"));
exitAction->setStatusTip(tr("Exit the application"));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
vehicleAddAction
= new QAction(tr
("&Add"),
this);
vehicleAddAction
->setIcon
(QIcon(":/Resources/AddVehicle.png"));
vehicleAddAction->setStatusTip(tr("Add a new vehicle to the list"));
connect(vehicleAddAction, SIGNAL(triggered()), this, SLOT(addVehicle()));
// .... more code
}
void MainWindow::createMenus()
{
oboxMenu = menuBar()->addMenu(tr("&OBox"));
oboxMenu->addAction(exitAction);
vehicleMenu = menuBar()->addMenu(tr("&Vehicle"));
vehicleMenu->addAction(vehicleAddAction);
vehicleMenu->addAction(vehicleRemoveAction);
vehicleMenu->addSeparator();
vehicleMenu->addAction(vehicleInfoAction);
// .... more code
}
void MainWindow::createActions()
{
exitAction = new QAction(tr("&Exit"), this);
//exitAction->setIcon(QIcon(":/Resources/exit.png"));
exitAction->setShortcut(tr("Ctrl+Q"));
exitAction->setStatusTip(tr("Exit the application"));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
vehicleAddAction = new QAction(tr("&Add"), this);
vehicleAddAction->setIcon(QIcon(":/Resources/AddVehicle.png"));
vehicleAddAction->setShortcut(QKeySequence::New);
vehicleAddAction->setStatusTip(tr("Add a new vehicle to the list"));
connect(vehicleAddAction, SIGNAL(triggered()), this, SLOT(addVehicle()));
// .... more code
}
void MainWindow::createMenus()
{
oboxMenu = menuBar()->addMenu(tr("&OBox"));
oboxMenu->addAction(exitAction);
vehicleMenu = menuBar()->addMenu(tr("&Vehicle"));
vehicleMenu->addAction(vehicleAddAction);
vehicleMenu->addAction(vehicleRemoveAction);
vehicleMenu->addSeparator();
vehicleMenu->addAction(vehicleInfoAction);
// .... more code
}
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
Bookmarks