PDA

View Full Version : Problems with QActions and Icons



franco.amato
14th September 2013, 00:37
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;

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
}


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->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
}

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,
Franco9590

franco.amato
14th September 2013, 06:05
More than 50 visits and 0 replies....maybe I posted a foo question?

wysota
14th September 2013, 08:32
Please provide a minimal compilable example reproducing the problem.

anda_skoa
14th September 2013, 10:51
Also try running with a different widget style, just to check that it is not the style that is at fault.

Cheers,
_

franco.amato
14th September 2013, 14:46
Hi thanx for the reply.
Here some code that should compile ( in my program ui is built using designer here no )


class MainWindow : public QMainWindow
{
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();

public:
explicit MainWindow(OBox* application);
static MainWindow* instance();
};

#endif // MAINWINDOW_H


// The mainwindow ctor ( I removed all non minimal code )

MainWindow::MainWindow() : QMainWindow(0)
{
createActions();
createMenus();
createToolBar();
}

Here I create actions ( only 3 just for test )

void MainWindow::createActions()
{
// I create only 3 actions just for test
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()));

vehicleRemoveAction = new QAction(tr("&Remove"), this);
vehicleRemoveAction->setIcon(QIcon(":/Resources/RemoveVehicle.png"));
vehicleRemoveAction->setShortcut(tr("Ctrl+R"));
vehicleRemoveAction->setStatusTip(tr("Remove a vehicle from the list"));
connect(vehicleAddAction, SIGNAL(triggered()), this, SLOT(removeVehicle()));

vehicleInfoAction = new QAction(tr("&Info"), this);
vehicleInfoAction->setIcon(QIcon(":/Resources/InfoVehicle.png"));
vehicleInfoAction->setShortcut(tr("Ctrl+I"));
vehicleInfoAction->setStatusTip(tr("Shows info about a vehicle"));
connect(vehicleInfoAction, SIGNAL(triggered()), this, SLOT(infoVehicle()));
}


void MainWindow::createMenus()
{
oboxMenu = menuBar()->addMenu(tr("&OBox"));

vehicleMenu = menuBar()->addMenu(tr("&Vehicle"));
vehicleMenu->addAction(vehicleAddAction);
vehicleMenu->addAction(vehicleRemoveAction);
vehicleMenu->addSeparator();
vehicleMenu->addAction(vehicleInfoAction);
}


void MainWindow::createToolBar()
{
mainToolBar = addToolBar(tr("&OBox"));
mainToolBar->addAction(vehicleAddAction);
mainToolBar->addAction(vehicleRemoveAction);
mainToolBar->addAction(vehicleInfoAction);
}

I also attach the 3 icons (64x64)

959195929593.
Regards

Added after 14 minutes:

Hi anda_skoa,
which widget should I modify?
Bye

anda_skoa
15th September 2013, 11:33
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,
_