Qt Jambi Home

com.trolltech.qt.gui
Class QMenuBar

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.gui.QMenuBar
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QMenuBar
extends QWidget

The QMenuBar class provides a horizontal menu bar.

A menu bar consists of a list of pull-down menu items. You add menu items with addMenu. For example, asuming that menubar is a pointer to a QMenuBar and fileMenu is a pointer to a QMenu, the following statement inserts the menu into the menu bar:

    menubar->addMenu(fileMenu);

The ampersand in the menu item's text sets Alt+F as a shortcut for this menu. (You can use "&&" to get a real ampersand in the menu bar.)

There is no need to lay out a menu bar. It automatically sets its own geometry to the top of the parent widget and changes it appropriately whenever the parent is resized.

In most main window style applications you would use the menuBar() provided in QMainWindow, adding QMenus to the menu bar and adding QActions to the popup menus.

Example (from the Menus example):

        fileMenu = menuBar()->addMenu(tr("&File"));
        fileMenu->addAction(newAct);

Menu items may be removed with removeAction.

Platform Dependent Look and Feel

Different platforms have different requirements for the appearance of menu bars and their behavior when the user interacts with them. For example, Windows systems are often configured so that the underlined character mnemonics that indicate keyboard shortcuts for items in the menu bar are only shown when the Alt key is pressed.

A menu bar shown in the Plastique widget style.The Plastique widget style, like most other styles, handles the Help menu in the same way as it handles any other menu.
A menu bar shown in the Motif widget style.The Motif widget style treats Help menus in a special way, placing them at right-hand end of the menu bar.

QMenuBar on Qt/Mac

QMenuBar on Qt/Mac is a wrapper for using the system-wide menu bar. If you have multiple menu bars in one dialog the outermost menu bar (normally inside a widget with widget flag Qt::Window) will be used for the system-wide menu bar.

Qt/Mac also provides a menu bar merging feature to make QMenuBar conform more closely to accepted Mac OS X menu bar layout. The merging functionality is based on string matching the title of a QMenu entry. These strings are translated (using QObject::tr()) in the "QMenuBar" context. If an entry is moved its slots will still fire as if it was in the original place. The table below outlines the strings looked for and where the entry is placed if matched:

String matchesPlacementNotes
about.*Application Menu | About <application name>If this entry is not found no About item will appear in the Application Menu
config, options, setup, settings or preferencesApplication Menu | PreferencesIf this entry is not found the Settings item will be disabled
quit or exitApplication Menu | Quit <application name>If this entry is not found a default Quit item will be created to call QApplication::quit()

You can override this behavior by using the QAction::menuRole() property.

If you wish to make all windows in a Mac application share the same menu bar, you need to create a menu bar that does not have a parent. The menu bar is created like this:

      QMenuBar *menuBar = new QMenuBar(0);

Note: The text used for the application name in the menu bar is obtained from the value set in the Info.plist file in the application's bundle. See Deploying an Application on Qt/Mac for more information.

Examples

The Menus example shows how to use QMenuBar and QMenu. The other main window application examples also provide menus using these classes.

See Also:
QMenu, QShortcut, QAction, Introduction to Apple Human Interface Guidelines, GUI Design Handbook: Menu Bar, Menus Example

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
QWidget.RenderFlag, QWidget.RenderFlags
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 QSignalEmitter.Signal1<QAction> hovered
          This signal is emitted when a menu action is highlighted; action is the action that caused the event to be sent.
 QSignalEmitter.Signal1<QAction> triggered
          This signal is emitted when an action in a menu belonging to this menubar is triggered as a result of a mouse click; action is the action that caused the signal to be emitted.
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Constructor Summary
QMenuBar()
          Equivalent to QMenuBar(0).
QMenuBar(QWidget parent)
          Constructs a menu bar with parent parent.
 
Method Summary
 QAction actionAt(QPoint arg__1)
          
protected  void actionEvent(QActionEvent arg__1)
          

This event handler is called with the given arg__1 whenever the widget's actions are changed.

 QRect actionGeometry(QAction arg__1)
          
 QAction activeAction()
          Returns the QAction that is currently highlighted.
 QAction addAction(java.lang.String text)
          This convenience function creates a new action with text.
 QAction addAction(java.lang.String text, java.lang.Object receiver, java.lang.String method)
          This convenience function creates a new action with the given text.
 QAction addAction(java.lang.String text, QSignalEmitter.AbstractSignal signal)
          This convenience function creates a new action with the given text.
 QMenu addMenu(QIcon icon, java.lang.String title)
          Appends a new QMenu with icon and title to the menu bar.
 QAction addMenu(QMenu menu)
          Appends menu to the menu bar.
 QMenu addMenu(java.lang.String title)
          Appends a new QMenu with title to the menu bar.
 QAction addSeparator()
          Appends a separator to the menu.
protected  void changeEvent(QEvent arg__1)
          

This event handler can be reimplemented to handle state changes.

 void clear()
          Removes all the actions from the menu bar.
 QWidget cornerWidget()
          Equivalent to cornerWidget(Qt::TopRightCorner).
 QWidget cornerWidget(Qt.Corner corner)
          
 boolean event(QEvent arg__1)
          

This is the main event handler; it handles event arg__1.

 boolean eventFilter(QObject arg__1, QEvent arg__2)
          

Filters events if this object has been installed as an event filter for the arg__1 object.

protected  void focusInEvent(QFocusEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget.

protected  void focusOutEvent(QFocusEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget.

static QMenuBar fromNativePointer(QNativePointer nativePointer)
          This function returns the QMenuBar instance pointed to by nativePointer
 int heightForWidth(int arg__1)
          

Returns the preferred height for this widget, given the width arg__1.

protected  void initStyleOption(QStyleOptionMenuItem option, QAction action)
          Initialize option with the values from the menu bar and information from action.
 QAction insertMenu(QAction before, QMenu menu)
          This convenience function inserts menu before action before and returns the menus menuAction().
 QAction insertSeparator(QAction before)
          This convenience function creates a new separator action, i.e. an action with QAction::isSeparator() returning true.
 boolean isDefaultUp()
          Returns the popup orientation.
protected  void keyPressEvent(QKeyEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive key press events for the widget.

protected  void leaveEvent(QEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the arg__1 parameter.

 QSize minimumSizeHint()
          

Returns the recommended minimum size for the widget.

protected  void mouseMoveEvent(QMouseEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse move events for the widget.

protected  void mousePressEvent(QMouseEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse press events for the widget.

protected  void mouseReleaseEvent(QMouseEvent arg__1)
          

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse release events for the widget.

protected  void paintEvent(QPaintEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive paint events which are passed in the arg__1 parameter.

protected  void resizeEvent(QResizeEvent arg__1)
          

This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the arg__1 parameter.

 void setActiveAction(QAction action)
          Sets the currently highlighted action to action.
 void setCornerWidget(QWidget w)
          Equivalent to setCornerWidget(w, Qt::TopRightCorner).
 void setCornerWidget(QWidget w, Qt.Corner corner)
          
 void setDefaultUp(boolean arg__1)
          Sets the popup orientation to arg__1.
 void setVisible(boolean visible)
          

Sets whether the widget is visible to visible.

 QSize sizeHint()
          

Returns the recommended size for the widget.

 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuEvent, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, ensurePolished, enterEvent, focusNextChild, focusNextPrevChild, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyReleaseEvent, layout, layoutDirection, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumWidth, mouseDoubleClickEvent, mouseGrabber, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintEngine, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

hovered

public final QSignalEmitter.Signal1<QAction> hovered

This signal is emitted when a menu action is highlighted; action is the action that caused the event to be sent.

Often this is used to update status information.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QAction action)
void mySlot()
See Also:
triggered, QAction::hovered


triggered

public final QSignalEmitter.Signal1<QAction> triggered

This signal is emitted when an action in a menu belonging to this menubar is triggered as a result of a mouse click; action is the action that caused the signal to be emitted.

Normally, you connect each menu action to a single slot using QAction::triggered(), but sometimes you will want to connect several items to a single slot (most often if the user selects from an array). This signal is useful in such cases.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QAction action)
void mySlot()
See Also:
hovered, QAction::triggered

Constructor Detail

QMenuBar

public QMenuBar()

Equivalent to QMenuBar(0).


QMenuBar

public QMenuBar(QWidget parent)

Constructs a menu bar with parent parent.

Method Detail

actionAt

public final QAction actionAt(QPoint arg__1)


actionGeometry

public final QRect actionGeometry(QAction arg__1)


activeAction

public final QAction activeAction()

Returns the QAction that is currently highlighted. A null pointer will be returned if no action is currently selected.

See Also:
setActiveAction

addAction

public final QAction addAction(java.lang.String text)

This convenience function creates a new action with text. The function adds the newly created action to the menu's list of actions, and returns it.

See Also:
QWidget::addAction

addMenu

public final QMenu addMenu(java.lang.String title)

Appends a new QMenu with title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu.

See Also:
QWidget::addAction, QMenu::menuAction

addMenu

public final QMenu addMenu(QIcon icon,
                           java.lang.String title)

Appends a new QMenu with icon and title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu.

See Also:
QWidget::addAction, QMenu::menuAction

addMenu

public final QAction addMenu(QMenu menu)

Appends menu to the menu bar. Returns the menu's menuAction().

See Also:
QWidget::addAction, QMenu::menuAction

addSeparator

public final QAction addSeparator()

Appends a separator to the menu.


clear

public final void clear()

Removes all the actions from the menu bar.

See Also:
removeAction

cornerWidget

public final QWidget cornerWidget()

Equivalent to cornerWidget(Qt::TopRightCorner).


cornerWidget

public final QWidget cornerWidget(Qt.Corner corner)

See Also:
setCornerWidget

insertMenu

public final QAction insertMenu(QAction before,
                                QMenu menu)

This convenience function inserts menu before action before and returns the menus menuAction().

See Also:
QWidget::insertAction, addMenu

insertSeparator

public final QAction insertSeparator(QAction before)

This convenience function creates a new separator action, i.e. an action with QAction::isSeparator() returning true. The function inserts the newly created action into this menu bar's list of actions before action before and returns it.

See Also:
QWidget::insertAction, addSeparator

isDefaultUp

public final boolean isDefaultUp()

Returns the popup orientation.

The default popup orientation. By default, menus pop "down" the screen. By setting the property to true, the menu will pop "up". You might call this for menus that are below the document to which they refer.

If the menu would not fit on the screen, the other direction is used automatically.


setActiveAction

public final void setActiveAction(QAction action)

Sets the currently highlighted action to action.

See Also:
activeAction

setCornerWidget

public final void setCornerWidget(QWidget w)

Equivalent to setCornerWidget(w, Qt::TopRightCorner).


setCornerWidget

public final void setCornerWidget(QWidget w,
                                  Qt.Corner corner)

See Also:
cornerWidget

setDefaultUp

public final void setDefaultUp(boolean arg__1)

Sets the popup orientation to arg__1.

The default popup orientation. By default, menus pop "down" the screen. By setting the property to true, the menu will pop "up". You might call this for menus that are below the document to which they refer.

If the menu would not fit on the screen, the other direction is used automatically.

See Also:
isDefaultUp

actionEvent

protected void actionEvent(QActionEvent arg__1)

This event handler is called with the given arg__1 whenever the widget's actions are changed.

Overrides:
actionEvent in class QWidget
See Also:
addAction, insertAction, removeAction, actions, QActionEvent

changeEvent

protected void changeEvent(QEvent arg__1)

This event handler can be reimplemented to handle state changes.

The state being changed in this event can be retrieved through event arg__1.

Change events include: QEvent::ToolBarChange, QEvent::ActivationChange, QEvent::EnabledChange, QEvent::FontChange, QEvent::StyleChange, QEvent::PaletteChange, QEvent::WindowTitleChange, QEvent::IconTextChange, QEvent::ModifiedChange, QEvent::MouseTrackingChange, QEvent::ParentChange, QEvent::WindowStateChange, QEvent::LanguageChange, QEvent::LocaleChange, QEvent::LayoutDirectionChange.

Overrides:
changeEvent in class QWidget

event

public boolean event(QEvent arg__1)

This is the main event handler; it handles event arg__1. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

Key press and release events are treated differently from other events. event checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event calls keyPressEvent.

Mouse and tablet event handling is also slightly special: only when the widget is enabled, event will call the specialized handlers such as mousePressEvent; otherwise it will discard the event.

This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.

Overrides:
event in class QWidget
See Also:
closeEvent, focusInEvent, focusOutEvent, enterEvent, keyPressEvent, keyReleaseEvent, leaveEvent, mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, moveEvent, paintEvent, resizeEvent, QObject::event, QObject::timerEvent

eventFilter

public boolean eventFilter(QObject arg__1,
                           QEvent arg__2)

Filters events if this object has been installed as an event filter for the arg__1 object.

In your reimplementation of this function, if you want to filter the arg__2 out, i.e. stop it being handled further, return true; otherwise return false.

Example:

    class MainWindow : public QMainWindow
    {
    public:
        MainWindow();

    protected:
        bool eventFilter(QObject *obj, QEvent *ev);

    private:
        QTextEdit *textEdit;
    };

    MainWindow::MainWindow()
    {
        textEdit = new QTextEdit;
        setCentralWidget(textEdit);

        textEdit->installEventFilter(this);
    }

    bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    {
        if (obj == textEdit) {
            if (event->type() == QEvent::KeyPress) {
                QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                qDebug() << "Ate key press" << keyEvent->key();
                return true;
            } else {
                return false;
            }
        } else {
            // pass the event on to the parent class
            return QMainWindow::eventFilter(obj, event);
        }
    }

Notice in the example above that unhandled events are passed to the base class's eventFilter function, since the base class might have reimplemented eventFilter for its own internal purposes.

Warning: If you delete the receiver object in this function, be sure to return true. Otherwise, Qt will forward the event to the deleted object and the program might crash.

Overrides:
eventFilter in class QObject
See Also:
installEventFilter

focusInEvent

protected void focusInEvent(QFocusEvent arg__1)

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget. The event is passed in the arg__1 parameter

A widget normally must setFocusPolicy to something other than Qt::NoFocus in order to receive focus events. (Note that the application programmer can call setFocus on any widget, even those that do not normally accept focus.)

The default implementation updates the widget (except for windows that do not specify a focusPolicy).

Overrides:
focusInEvent in class QWidget
See Also:
focusOutEvent, setFocusPolicy, keyPressEvent, keyReleaseEvent, event, QFocusEvent

focusOutEvent

protected void focusOutEvent(QFocusEvent arg__1)

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget. The events is passed in the arg__1 parameter.

A widget normally must setFocusPolicy to something other than Qt::NoFocus in order to receive focus events. (Note that the application programmer can call setFocus on any widget, even those that do not normally accept focus.)

The default implementation updates the widget (except for windows that do not specify a focusPolicy).

Overrides:
focusOutEvent in class QWidget
See Also:
focusInEvent, setFocusPolicy, keyPressEvent, keyReleaseEvent, event, QFocusEvent

heightForWidth

public int heightForWidth(int arg__1)

Returns the preferred height for this widget, given the width arg__1.

If this widget has a layout, the default implementation returns the layout's preferred height. if there is no layout, the default implementation returns -1 indicating that the preferred height does not depend on the width.

Overrides:
heightForWidth in class QWidget

keyPressEvent

protected void keyPressEvent(QKeyEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive key press events for the widget.

A widget must call setFocusPolicy to accept focus initially and have focus in order to receive a key press event.

If you reimplement this handler, it is very important that you ignore() the event if you do not understand it, so that the widget's parent can interpret it.

The default implementation closes popup widgets if the user presses Esc. Otherwise the event is ignored.

Overrides:
keyPressEvent in class QWidget
See Also:
keyReleaseEvent, QKeyEvent::ignore, setFocusPolicy, focusInEvent, focusOutEvent, event, QKeyEvent, Tetrix Example

leaveEvent

protected void leaveEvent(QEvent arg__1)

This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the arg__1 parameter.

A leave event is sent to the widget when the mouse cursor leaves the widget.

Overrides:
leaveEvent in class QWidget
See Also:
enterEvent, mouseMoveEvent, event

minimumSizeHint

public QSize minimumSizeHint()

Returns the recommended minimum size for the widget.

If the value of this property is an invalid size, no minimum size is recommended.

The default implementation of minimumSizeHint returns an invalid size if there is no layout for this widget, and returns the layout's minimum size otherwise. Most built-in widgets reimplement minimumSizeHint.

QLayout will never resize a widget to a size smaller than the minimum size hint unless minimumSize is set or the size policy is set to QSizePolicy::Ignore. If minimumSize is set, the minimum size hint will be ignored.

Overrides:
minimumSizeHint in class QWidget
See Also:
QSize::isValid, resize, setMinimumSize, sizePolicy

mouseMoveEvent

protected void mouseMoveEvent(QMouseEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse move events for the widget.

If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.

QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.

Overrides:
mouseMoveEvent in class QWidget
See Also:
setMouseTracking, mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, event, QMouseEvent, Example

mousePressEvent

protected void mousePressEvent(QMouseEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent the mouseReleaseEvent may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

Overrides:
mousePressEvent in class QWidget
See Also:
mouseReleaseEvent, mouseDoubleClickEvent, mouseMoveEvent, event, QMouseEvent, Example

mouseReleaseEvent

protected void mouseReleaseEvent(QMouseEvent arg__1)

This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse release events for the widget.

Overrides:
mouseReleaseEvent in class QWidget
See Also:
mousePressEvent, mouseDoubleClickEvent, mouseMoveEvent, event, QMouseEvent, Example

paintEvent

protected void paintEvent(QPaintEvent arg__1)

This event handler can be reimplemented in a subclass to receive paint events which are passed in the arg__1 parameter.

A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint or update, or because the widget was obscured and has now been uncovered, or for many other reasons.

Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.

Qt also tries to speed up painting by merging multiple paint events into one. When update is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint does not permit this optimization, so we suggest using update whenever possible.

When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.

The background can be set using setBackgroundRole and setPalette.

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent to avoid flicker.

Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:

    ...
    extern void qt_x11_set_global_double_buffer(bool);
    qt_x11_set_global_double_buffer(false);
    ...

Note: In general, one should refrain from calling update or repaint inside of paintEvent. For example, calling update or repaint on children inside a paintEvent results in undefined behavior; the child may or may not get a paint event.

Overrides:
paintEvent in class QWidget
See Also:
event, repaint, update, QPainter, QPixmap, QPaintEvent, Analog Clock Example

resizeEvent

protected void resizeEvent(QResizeEvent arg__1)

This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the arg__1 parameter. When resizeEvent is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize().

The widget will be erased and receive a paint event immediately after processing the resize event. No drawing need be (or should be) done inside this handler.

Overrides:
resizeEvent in class QWidget
See Also:
moveEvent, event, resize, QResizeEvent, paintEvent, Example

setVisible

public void setVisible(boolean visible)

Sets whether the widget is visible to visible.

Calling setVisible(true) or show sets the widget to visible status if all its parent widgets up to the window are visible. If an ancestor is not visible, the widget won't become visible until all its ancestors are shown. If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown. If the widget has not been resized yet, Qt will adjust the widget's size to a useful default using adjustSize.

Calling setVisible(false) or hide hides a widget explicitly. An explicitly hidden widget will never become visible, even if all its ancestors become visible, unless you show it.

A widget receives show and hide events when its visibility status changes. Between a hide and a show event, there is no need to waste CPU cycles preparing or displaying information to the user. A video application, for example, might simply stop generating new frames.

A widget that happens to be obscured by other windows on the screen is considered to be visible. The same applies to iconified windows and windows that exist on another virtual desktop (on platforms that support this concept). A widget receives spontaneous show and hide events when its mapping status is changed by the window system, e.g. a spontaneous hide event when the user minimizes the window, and a spontaneous show event when the window is restored again.

You almost never have to reimplement the setVisible function. If you need to change some settings before a widget is shown, use showEvent instead. If you need to do some delayed initialization use the Polish event delivered to the event function.

Overrides:
setVisible in class QWidget
See Also:
show, hide, isHidden, isVisibleTo, isMinimized, showEvent, hideEvent

sizeHint

public QSize sizeHint()

Returns the recommended size for the widget.

If the value of this property is an invalid size, no size is recommended.

The default implementation of sizeHint returns an invalid size if there is no layout for this widget, and returns the layout's preferred size otherwise.

Overrides:
sizeHint in class QWidget
See Also:
QSize::isValid, minimumSizeHint, sizePolicy, setMinimumSize, updateGeometry

fromNativePointer

public static QMenuBar fromNativePointer(QNativePointer nativePointer)
This function returns the QMenuBar instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

addAction

public final QAction addAction(java.lang.String text,
                               java.lang.Object receiver,
                               java.lang.String method)
This convenience function creates a new action with the given text. The action's triggered() signal is connected to the receiver's method slot. The function adds the newly created action to the menu's list of actions and returns it.


addAction

public final QAction addAction(java.lang.String text,
                               QSignalEmitter.AbstractSignal signal)
This convenience function creates a new action with the given text. The action's triggered() signal is connected to the signal. The function adds the newly created action to the menu's list of actions and returns it.


initStyleOption

protected final void initStyleOption(QStyleOptionMenuItem option,
                                     QAction action)
Initialize option with the values from the menu bar and information from action. This method is useful for subclasses when they need a QStyleOptionMenuItem, but don't want to fill in all the information themselves.


Qt Jambi Home