QT learning notes _ establish connections and qt learning notes

Source: Internet
Author: User

QT learning notes _ establish connections and qt learning notes

A connection is called a connection, that is, the user's response to the program after clicking a button. This time, an exit button is written.

// Establish a connection to respond to the event # include <QApplication> # include <QPushButton> int main (int argc, char * argv []) {QApplication app (argc, argv ); QPushButton * button = new QPushButton ("Quit"); QObject: connect (button, SIGNAL (clicked (), & app, SLOT (quit ())); button-> show (); return app.exe c ();}

:


Establish a connection between C ++ GUI and Qt, and connect signals and slots

Void QSpinBox: valueChanged (int I) [signal]
This signal is emitted whenever the spin box's value is changed. The new value's integer value is passed in I.
When the value of spin box changes, this signal will be sent. The latest value of spin box is passed through parameter I.

Value: int
This property holds the slider's current value.
The slider forces the value to be within the legal range: minimum <= value <= maximum.
Changing the value also changes the sliderPosition.
This attribute is the current value of the slider. The slider will force the value to be within the valid range between the minimum and maximum values. The position of the slider's slide block will change with this value.
Access functions:
Int value () const
Void setValue (int)
Notifier signal:
Notification signal:
Void valueChanged (int value)
You can use setRange (int min, int max) to set the range)
You can use setSingleStep (int) to set the pace)
PS: The Best Way to learn QT is assistant.

My Qt Study Notes 4 how to pop up the right-click menu in the QWidget window

Solution 1: Add QActions to a QWidget and set the contextMenuPolicy attribute of QWidget to the value of Qt: ActionsContextMenu. This makes the window menu a right-click menu consisting of the added QActions. 1: MyWidget (QWidget * parent) 2: QWidget (parent) 3: {4: setWindowTitle (tr (Context Menu Show 1); 5: // Add QActions6: addAction (newQAction (tr (& Open), this) for the window; 7: addAction (newQAction (QIcon (:/images/mark.png ), tr (& Mark), this); 8: addAction (newQAction (tr (& Quit), this); 9: // set the value of contextMenuPolicy to '10: setContextMenuPolicy (Qt: ActionsContextMenu) consisting of menu items with Actions as the pop-up menu; 11:} effect: Solution 2: override the protected virtual function of QWidget Void QWidget: contextMenuEvent (QContextMenuEvent * event) [virtual protected]. Set the contextMenuPolicy attribute of QWidget to the value of Qt: DefaultContextMenu, which is the default value and does not need to be displayed. 1: MyWidget (QWidget * parent) 2: QWidget (parent) 3: {4: setWindowTitle (tr (Context Menu Show 2); 5: setContextMenuPolicy (Qt:: DefaultContextMenu); // you do not need to set it. The default value is 6:} 7: 8: 9: voidMyWidget: contextMenuEvent (QContextMenuEvent * event) 10: {11: QMenu * menu = newQMenu (this); 12: menu-addAction (newQAction (tr (& Open), menu); 13: menu-addAction (newQAction (QIcon (: /images/mark.png), tr (& Mark), menu); 14: menu-addAction (NewQAction (tr (& Quit), menu); 15: menu-move (cursor (). pos (); // place the menu on the coordinates of the mouse. 16: menu-show (); 17:} effect: the above shows a new menu and some menu items in the contextMenuEvent function body for demonstration.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.