Google マップのズームイン、ズームアウトに似たボタンを作成しようとしています。アイコンと同じ大きさのボタンが欲しい:
http://codegeekz.com/wp-content/uploads/google-maps-jquery.jpg
(画像を掲載せず申し訳ありません。評判が足りないようです)。
QAction を使用しようとしていますが、何らかの理由でボタンが表示されません。QAction を使用して別のプロジェクトでボタンを作成しましたが、関連するすべてのコードをコピーしてもうまくいきませんでした (単にインスタンスが表示されません)。これらは必需品です:
メインウィンドウ.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QAction>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
protected slots:
void addEntry();
private:
QAction *addButton;
};
#endif // MAINWINDOW_H
メインウィンドウ.cpp
#include "mainwindow.h"
#include <QHBoxLayout>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QWidget *window = new QWidget;
QVBoxLayout *container = new QVBoxLayout();
//Horizontal add/subtract layout------------------------------------
QHBoxLayout *layer1 = new QHBoxLayout();
QAction *addButton = new QAction((QIcon("/home/kyle/Desktop/add1.png")),"Add Entry", this);
addAction(addButton);
connect(addButton, SIGNAL(triggered()), this, SLOT(addEntry()));
//Scroll Layout------------------------------------
QHBoxLayout *layer2 = new QHBoxLayout();
...
container->addLayout(layer1);
container->addLayout(layer2);
window->setLayout(container);
setCentralWidget(window);
}
void
MainWindow::addEntry(){
...
}
私は持っている:
- 空のウィジェットで addAction() を試し、それをレイアウトに追加しました。
- .h ファイルで QAction オブジェクトを宣言 (QPainter を使用する際の一般的な問題)
- QPushButton を使用してみました (非常に醜いですが動作します)。
何が間違っているか、または他のボタンのようなオブジェクトの推奨事項についてのアイデアをいただければ幸いです。質問もお気軽にどうぞ。最終的に作成したいボタンは、QHBoxLayout で操作できる小さなウィジェットです。