Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Info needed about drawing and the Paint System
Forum Updated to NodeBB v4.3 + New Features

Info needed about drawing and the Paint System

Scheduled Pinned Locked Moved General and Desktop
16 Posts 6 Posters 6.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vishwajeet
    wrote on last edited by
    #3

    If you want to draw custom content within form and to that u r referring as paint system ? then you can skip that by using Qt webkit module and keeping simple html form.

    Born To Code !!!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dialingo
      wrote on last edited by
      #4

      Qt comes with a tool called designer.
      Invoke it and see how convenient it is to drag and drop available widgets like buttons and line edits into a form. The result can be further processed and compiled.

      There is a very small tutorial which lets you assemble widgets with code only (without designer):
      http://doc.qt.nokia.com/4.7/gettingstartedqt.html
      Try to work through it and the solution to your problem will become visible.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nevering
        wrote on last edited by
        #5

        surprised that everyone is asking about the paint system.

        http://doc.qt.nokia.com/4.7-snapshot/paintsystem.html

        So far I haven't found out how to draw a line in a widget. I understand how to drop textbox widgets etc. I need to create these forms on the fly by reading an external file. So I'll need a form engine. What I have found so far is that QT wants to do drawline along with the painter.

        what I've run across are things like this

        @
        #include <QtGui>

        class MyWidget : public QWidget
        {
        public:
        MyWidget();

        protected:
        void paintEvent(QPaintEvent *);
        };

        MyWidget::MyWidget()
        {
        QPalette palette(MyWidget::palette());
        palette.setColor(backgroundRole(), Qt::white);
        setPalette(palette);
        }

        void MyWidget::paintEvent(QPaintEvent *)
        {
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setPen(Qt::darkGreen);
        painter.drawRect(1, 2, 6, 4);

        painter.setPen(Qt::darkGray);
        painter.drawLine(2, 8, 6, 2);
        

        }

        int main(int argc, char *argv[])
        {
        QApplication app(argc, argv);
        MyWidget widget;
        widget.show();
        return app.exec();
        }
        @

        I know I can drop a scroller in and have but what handles the drawing updates as things come in view if it's possible to do lines and boxes without the paint system ?

        [EDIT: code formatting, please use @-tags, Volker]

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vishwajeet
          wrote on last edited by
          #6

          Not sure what exactly you are looking for ?

          Born To Code !!!

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #7

            You are right, to draw real lines, you have to do your own painting. It was however not clear from your first question that this was the issue you were dealing with. Implementing your own widget like you did is an option then.

            However, if you just want lines as separators, you might look into using QFrame. It offers multiple styles, including VLine and HLine.

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #8

              I'd still prefer to do it in the paintEvent, but if you are averse to that one work around would be:

              1. Add dummy frames to parent widget
              2. Set position and size

              This is what designer does when you add a Horizontal line for example ...
              @
              line = new QFrame(centralWidget);
              line->setObjectName(QString::fromUtf8("line"));
              line->setFrameShape(QFrame::HLine);
              line->setFrameShadow(QFrame::Sunken);

                  gridLayout->addWidget(line, 0, 1, 1, 1);
              

              @

              edit: well Andre just beat me to it above .. but leaving my reply as is :)

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Nevering
                wrote on last edited by
                #9

                vishweqeet ... you can stop reading and replying please.

                Chetankjain. Thanks for your help and Andre.

                It seems clear now that to do any real line drawing and for a scrollable form I need the paint system.

                Another question would be ... I assume that you would have the paintevent in the widget your drawing on and draw to that widget rather than to the scroller.

                I'm trying to catch up on reading about this stuff as fast as I can, all I can find is 4.0 books. I'm guessing that 4.0 and 4.1 is very similar.

                thanks for all the help.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  Franzk
                  wrote on last edited by
                  #10

                  Your widget doesn't necessarily need to know about the scrolling. It just gets told which portion of itself to draw (event->rect()).

                  What goes for 4.0 goes for 4.1 as well. Some convenience things may have been added in the mean time though.

                  "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    Nevering
                    wrote on last edited by
                    #11

                    Don't quite get this, does this mean that a widget will automatically throw in scrolling ?

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      Franzk
                      wrote on last edited by
                      #12

                      No. It is QScrollArea that throws in scrolling. However, usually when scrolling is required, you only draw a portion of a widget. The widget only gets told to draw a certain portion of itself through the paint event. It is not (necessarily) aware of scrolling of any kind.

                      That means that you have your widget's paint event:
                      @MyWidget::paintEvent(QPaintEvent *e)
                      {
                      QRect paintRect = e->rect();
                      QPainter painter(this);
                      painter.fillRect(paintRect, Qt::blue); // whatever you like
                      // do some more painting if necessary
                      }@

                      And the QScrollArea around it:
                      @MySuperDuperProgram::MySuperDuperProgram(QWidget *parent)
                      {
                      // ...
                      QScrollArea *scrollArea = new QScrollArea(this);
                      scrollArea->setWidget(new MyWidget);
                      }@

                      QScrollArea takes care of scrolling, your widget takes care of whatever it is supposed to take care of.

                      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        Nevering
                        wrote on last edited by
                        #13

                        Ok, I basically get it.... You create a widget for drawing, give it a paintevent for painting when needed. Hook it up to a Scrollarea. And the scroller works automagically (as it should) on the widget.

                        Sound good.

                        thanks

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          Nevering
                          wrote on last edited by
                          #14

                          another question if you don't mind. If I drop a Scrollarea onto a Widget in QT Creator. It it automatically hooked up to the widget or do I need to do that in code ?

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            saidiahd
                            wrote on last edited by
                            #15

                            very interesting...

                            "Learn from yesterday, live for today, hope for tomorrow." - Albert Einstein -

                            1 Reply Last reply
                            0
                            • F Offline
                              F Offline
                              Franzk
                              wrote on last edited by
                              #16

                              [quote author="Nevering" date="1299016007"]another question if you don't mind. If I drop a Scrollarea onto a Widget in QT Creator. It it automatically hooked up to the widget or do I need to do that in code ?[/quote]If you drop a scroll area on a widget, that widget has a scroll area, but the widget is not automatically scrolled. You would have to add the widget to the scroll area.

                              "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved