1 Attachment(s)
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
Code:
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
}
and in mainwindow.cpp
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->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,
FrancoAttachment 9590
Re: Problems with QActions and Icons
More than 50 visits and 0 replies....maybe I posted a foo question?
Re: Problems with QActions and Icons
Please provide a minimal compilable example reproducing the problem.
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,
_
3 Attachment(s)
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 )
Code:
{
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();
public:
explicit MainWindow(OBox* application);
static MainWindow* instance();
};
#endif // MAINWINDOW_H
// The mainwindow ctor ( I removed all non minimal code )
Code:
{
createActions();
createMenus();
createToolBar();
}
Here I create actions ( only 3 just for test )
Code:
void MainWindow::createActions()
{
// I create only 3 actions just for test
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()));
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()));
}
Code:
void MainWindow::createMenus()
{
oboxMenu = menuBar()->addMenu(tr("&OBox"));
vehicleMenu = menuBar()->addMenu(tr("&Vehicle"));
vehicleMenu->addAction(vehicleAddAction);
vehicleMenu->addAction(vehicleRemoveAction);
vehicleMenu->addSeparator();
vehicleMenu->addAction(vehicleInfoAction);
}
Code:
void MainWindow::createToolBar()
{
mainToolBar = addToolBar(tr("&OBox"));
mainToolBar->addAction(vehicleAddAction);
mainToolBar->addAction(vehicleRemoveAction);
mainToolBar->addAction(vehicleInfoAction);
}
I also attach the 3 icons (64x64)
Attachment 9591Attachment 9592Attachment 9593.
Regards
Added after 14 minutes:
Hi anda_skoa,
which widget should I modify?
Bye
Re: Problems with QActions and Icons
Quote:
Originally Posted by
franco.amato
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,
_