Chris Guan's Profile

Member since Nov 08, 2007, follows 4 people, 0 public groups, 418 public bookmarks (473 total).

More »
Tags

Recent Tags:
Top Tags:

More »
Recent Bookmarks and Annotations

  • Painting in Qt4 on 2009-09-20
    •  QPen pen(Qt::black, 2, Qt::SolidLine);


      We create a QPen object. The pen is solid, 2px thick and of black colour.
      The pen is used to draw lines and outlines of shapes.



       QPainter painter(this);


      We create a QPainter object.



       painter.drawLine(20, 40, 250, 40);


      Here we paint the first line. The four parameters are coordinates of two points on the window.



       pen.setStyle(Qt::DashLine);


      This code line sets a different pen style.

    •  painter.setBrush(QBrush("#c56c00"));
      painter.drawRect(10, 15, 90, 60);


      The QBrush class defines the fill pattern of shapes drawn by QPainter.
      The drawRect() method draws the rectangle. It draws a rectangle with upper left corner at x, y point and with the given width and height. To specify a color, we used a hexadecimal notation.

    • 12 more annotations...
  • Qt4 widgets II on 2009-09-20
    •  lw = new QListWidget(this);
      lw->addItem("The Omen");
      lw->addItem("The Exorcist");
      lw->addItem("Notes on a scandal");
      lw->addItem("Fargo");
      lw->addItem("Capote);


      The QListWidget is created and filled with five items.

    • void ListWidget::addItem()
      {
      QString item = QInputDialog::getText(this, "Item",
      "Enter new item");
      item = item.simplified();
      if (!item.isEmpty()) {
      lw->addItem(item);
      int r = lw->count() - 1;
      lw->setCurrentRow(r);
      }
      }


      The addItem() method adds a new item to the list widget.
      The method pops up a dialog. The dialog returns a string value. We remove possible white spaces from the string using
      the simplified() method. If the returned string is not empty, we add it to the list widget.
      Finally, we highlight the currently inserted item.

    • 3 more annotations...
  • Qt4 widgets on 2009-09-20
    • connect(slider, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));


      In this example, we connect the valueChanged() signal to the predefined setNum() slot.

    • SpinBox::SpinBox(QWidget *parent)
      : QWidget(parent)
      {
      spinbox = new QSpinBox(this);
      spinbox->setGeometry(50, 50, 60, 30);

      connect(spinbox, SIGNAL(valueChanged(int)),
      this, SLOT(setTitle(int)));

      }

      void SpinBox::setTitle(int val)
      {
      setWindowTitle(QString::number(val));
      }
    • 2 more annotations...
  • Events and signals in Qt4 on 2009-09-20
    • connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));


      The connect() method connects a signal to the slot. When we click on the quit button,
      the clicked() signal is generated. The qApp is a global pointer to the
      application object. It is defined in the <QApplication> header file. The quit() method
      is called, when the clicked signal is emitted.

    • void KeyPress::keyPressEvent(QKeyEvent *event)
      {
      if (event->key() == Qt::Key_Escape) {
      qApp->quit();
      }
      }


      One of the ways of working with events in Qt4 programming library is to reimplement an event handler.
      The QKeyEvent is an event object, which holds information about what has happened.
      In our case, we use the event object to determine, which key was actually pressed.

    • 4 more annotations...
  • Layout management in Qt4 on 2009-09-19
    • QTextEdit *edit = new QTextEdit(this);
      edit->setGeometry(5, 5, 200, 150);
    • QVBoxLayout *vbox = new QVBoxLayout(this);
      QHBoxLayout *hbox = new QHBoxLayout();

      ok = new QPushButton("OK", this);
      apply = new QPushButton("Apply", this);

      hbox->addWidget(ok, 1, Qt::AlignRight);
      hbox->addWidget(apply, 0, Qt::AlignRight);

      vbox->addStretch(1);
      vbox->addLayout(hbox);
    • 3 more annotations...
  • Menus and toolbars in Qt4 on 2009-09-19
    • SimpleMenu::SimpleMenu(QWidget *parent)
      : QMainWindow(parent)
      {

      QAction *quit = new QAction("&Quit", this);

      QMenu *file;
      file = menuBar()->addMenu("&File");
      file->addAction(quit);

      connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));

      }
    • QPixmap newpix("new.png");
      QPixmap openpix("open.png");
      QPixmap quitpix("quit.png");

      QAction *newa = new QAction(newpix, "&New", this);
      QAction *open = new QAction(openpix, "&Open", this);
      QAction *quit = new QAction(quitpix, "&Quit", this);
      quit->setShortcut(tr("CTRL+Q"));
    • 4 more annotations...
  • First programs in Qt4 on 2009-09-18
    • #include <QApplication>
      #include <QWidget>

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      QWidget window;

      window.resize(250, 150);
      window.setWindowTitle("Simple example");
      window.show();

      return app.exec();
      }
    • QDesktopWidget *desktop = QApplication::desktop();

      screenWidth = desktop->width();
      screenHeight = desktop->height();

      x = (screenWidth - WIDTH) / 2;
      y = (screenHeight - HEIGHT) / 2;

      window.resize(WIDTH, HEIGHT);
    • 3 more annotations...
  • Qt4 utility classes on 2009-09-18
    • std::cout << "console application\n";
    • QTextStream out(stdout);
      out << "console application\n";
    • 11 more annotations...
  • Introduction to Qt4 toolkit on 2009-09-18
      • Trolltech introduced five new technologies.



        • Tulip - a set of template container classes
        • Interview - a model/view architecture for viewing items
        • Arthur - the painting framework
        • Scribe - the Unicode text renderer
        • Mainwindow - a modern action-based mainwindow, toolbar, menu, and docking architecture



        The most exciting technology is definitely the Arthur painting framework.

    • Testing a small example





      Finally we will write a small code example.





      #include <QApplication>
      #include <QWidget>

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      QWidget window;

      window.resize(250, 150);
      window.setWindowTitle("Simple example");
      window.show();

      return app.exec();
      }


      To build this example, we will use a very handy tool called qmake.




      qmake -project
      qmake
      make
  • The Qt4 programming tutorial on 2009-09-18

Highlighter, Sticky notes, Tagging, Groups and Network: integrated suite dramatically boosting research productivity. Learn more »

Join Diigo