Difference between revisions of "Qt/Widgets/Cursor"
From ProgrammingExamples
< Qt
Daviddoria (Talk | contribs) (Created page with '==main.cpp== <source lang="cpp"> #include <QApplication> #include "form.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); MyForm form; form.show(…') |
(No difference)
|
Latest revision as of 20:25, 11 February 2011
main.cpp
#include <QApplication> #include "form.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); MyForm form; form.show(); return app.exec(); }
form.cpp
#include "form.h" #include <QCursor> MyForm::MyForm(QWidget *parent) : QWidget(parent) { setupUi(this); connect( this->pushButton, SIGNAL( clicked() ), this, SLOT(pushButton_clicked()) ); this->isWaiting = false; } void MyForm::pushButton_clicked() { this->label->setText("hello"); QCursor waitCursor; if(!isWaiting) { waitCursor.setShape(Qt::WaitCursor); isWaiting = true; } else { waitCursor.setShape(Qt::ArrowCursor); isWaiting = false; } this->setCursor(waitCursor); }
form.h
#ifndef FORM_H #define FORM_H #include "ui_form.h" class MyForm : public QWidget, private Ui::Form { Q_OBJECT public: MyForm(QWidget *parent = 0); public slots: void pushButton_clicked(); private: bool isWaiting; }; #endif
main.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>My Program</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>130</x>
<y>100</y>
<width>91</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>Click me</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>150</x>
<y>150</y>
<width>61</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Before click</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(Cursor) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) QT4_WRAP_UI(UISrcs form.ui) QT4_WRAP_CPP(MOCSrcs form.h) include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ADD_EXECUTABLE(Cursor main.cpp form.cpp ${MOCSrcs} ${UISrcs}) TARGET_LINK_LIBRARIES(Cursor ${QT_LIBRARIES})