nun habe ich mal ein button in meine neue toolbox reingepackt und wollte eine funktion vergeben das eben das eine toolbar dialog anzeigt wenn ich drauf klicke.
wie beim beim toolbar klick nur das der button es auch anzeigt.
also diese funktion muss etwas anders aussehen denke ich damit es eins
von den toolbar dialog aktiviert .
Code: Alles auswählen
connect(ui.transfersButton, SIGNAL(clicked()),
this, SLOT(4()));mein mainwindow.cpp:
Code: Alles auswählen
#include <QtGui>
#include <QMessageBox>
#include <QSystemTrayIcon>
#include <QString>
#include <QtDebug>
#include <QIcon>
#include <QPixmap>
#include "swaste.h"
#include "MainWindow.h"
#include "Preferences/PreferencesWindow.h"
#include "config/gconfig.h"
#define FONT QFont(tr("Arial"), 8)
/* Images for toolbar icons */
#define IMAGE_NETWORK ":/images/network-transmit-receive.svg"
#define IMAGE_SEARCH ":/images/system-search.svg"
#define IMAGE_TRANSFERS ":/images/system-software-update.svg"
#define IMAGE_SHARED_FILES ":/images/folder-remote.svg"
#define IMAGE_PREFERENCES ":/images/applications-system.svg"
#define IMAGE_CHAT ":/images/system-users.svg"
#define IMAGE_SWASTE ":/images/swaste16.png"
#define IMAGE_CHATS ":/images/internet-group-chat.svg"
/** Constructor */
MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
/* Invoke the Qt Designer generated QObject setup routine */
ui.setupUi(this);
GConfig config;
config.loadWidgetInformation(this);
/* Create the config pages and actions */
QActionGroup *grp = new QActionGroup(this);
ui.stackPages->add(new ConnectionsDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_NETWORK), tr("Network"), grp));
ui.stackPages->add(new ChatDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_CHAT), tr("Users"), grp));
ui.stackPages->add(new PeersDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_CHATS), tr("Chats"), grp));
ui.stackPages->add(new SearchDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_SEARCH), tr("Search"), grp));
ui.stackPages->add(new TransfersDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_TRANSFERS), tr("Transfers"), grp));
ui.stackPages->add(new SharedFilesDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_SHARED_FILES), tr("Shared Files"), grp));
//ui.stackPages->add(new StatisticDialog(ui.stackPages),
// createPageAction(QIcon(IMAGE_STATISTIC), tr("Statistics"), grp));
/* Create the toolbar */
ui.toolBar->addActions(grp->actions());
ui.toolBar->addSeparator();
connect(grp, SIGNAL(triggered(QAction *)), ui.stackPages, SLOT(showPage(QAction *)));
/* Create and bind the Preferences button */
addAction(new QAction(QIcon(IMAGE_PREFERENCES), tr("Preferences"), ui.toolBar),
SLOT(showPreferencesWindow()));
/* Select the first action */
grp->actions()[0]->setChecked(true);
/* Create the actions that will go in the tray menu */
createActions();
/** Creates a new action associated with a config page. */
QAction*
MainWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
{
QAction *action = new QAction(img, text, group);
action->setCheckable(true);
action->setFont(FONT);
return action;
}
/** Adds the given action to the toolbar and hooks its triggered() signal to
* the specified slot (if given). */
void
MainWindow::addAction(QAction *action, const char *slot)
{
action->setFont(FONT);
ui.toolBar->addAction(action);
connect(action, SIGNAL(triggered()), this, slot);
}
/** Overloads the default show so we can load settings */
void
MainWindow::show()
{
if (!this->isVisible()) {
QMainWindow::show();
} else {
QMainWindow::activateWindow();
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
QMainWindow::raise();
}
}
/** Shows the config dialog with focus set to the given page. */
void
MainWindow::show(Page page)
{
/* Show the dialog. */
show();
/* Set the focus to the specified page. */
ui.stackPages->setCurrentIndex((int)page);
}
/** Shows Preferences */
void MainWindow::showPreferencesWindow()
{
static PreferencesWindow* preferencesWindow = new PreferencesWindow(this);
preferencesWindow->show();
}
/** Destructor. */
MainWindow::~MainWindow()
{
}
/** Create and bind actions to events. Setup for initial
* tray menu configuration. */
void
MainWindow::createActions()
{
prefsAct = new QAction(QIcon(IMAGE_PREFERENCES), tr("Preferences"), this);
connect(prefsAct, SIGNAL(triggered()), this, SLOT(showPreferencesWindow()));
connect(ui.transfersButton, SIGNAL(clicked()),
this, SLOT(showtransfers()));
}Code: Alles auswählen
#ifndef _MainWindow_H
#define _MainWindow_H
#include <QMainWindow>
#include <QFileDialog>
#include <QSystemTrayIcon>
#include "ConnectionsDialog.h"
#include "PeersDialog.h"
#include "SearchDialog.h"
#include "TransfersDialog.h"
#include "ChatDialog.h"
#include "SharedFilesDialog.h"
#include "StatisticDialog.h"
#include "Preferences/PreferencesWindow.h"
#include "ui_MainWindow.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
/** Main dialog pages. */
enum Page {
Network = 0, /** Connections page. */
Users = 1, /** Users page. */
SharedDirectories = 2, /** Shared Directories page. */
Search = 3, /** Search page. */
Transfers = 4, /** Transfers page. */
Statistics = 5 /** Statistic page. */
};
/** Default Constructor */
MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Destructor. */
~MainWindow();
public slots:
/** Called when this dialog is to be displayed */
void show();
/** Shows the config dialog with focus set to the given page. */
void show(Page page);
/** Called when the user exits Rshare. */
// void close();
private slots:
void updateMenu();
void toggleVisibility();
void showMessage();
void balloonClicked();
void activated(QSystemTrayIcon::ActivationReason);
void changeIcon(int);
void showPreferencesWindow();
protected:
void closeEvent(QCloseEvent *);
private:
/** Loads the current configuration settings */
//void loadSettings();
/** Create the actions on the tray menu or menubar */
void createActions();
PreferencesWindow* _preferencesWindow;
/** Defines the actions for the tray menu */
QAction* prefsAct;
/** Creates a new action for a config page. */
QAction* createPageAction(QIcon img, QString text, QActionGroup *group);
/** Adds a new action to the toolbar. */
void addAction(QAction *action, const char *slot = 0);
QLineEdit *titleEdit;
QTextEdit *msgEdit;
QComboBox *typeCombo;
QSystemTrayIcon *trayIcon;
QAction *toggleVisibilityAction;
QMenu *menu;
QTextEdit *info;
QComboBox *iconPicker;
/** Qt Designer generated object */
Ui::MainWindow ui;
};
#endif