Results 1 to 8 of 8

Thread: problem in drwing several images on screen

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: problem in drwing several images on screen

    Thanks for answer!

    Quote Originally Posted by Talei View Post
    I guess that is a homework, and I saw that You are student of electrical engineering, so due to sentiment of the old days at uni (same department ), I prepared examples for you.

    As I said earlier, QLabel is not a way to go, because You really don't know haw many images user loads, and writing Your own code is, in my opinion, reinventing the wheel, and You are using qt because You don't want to do that, so why not to use a proper qt class to do the job for You?
    Here qLabImg_example..zip is an example that change layout to horizontal, code is buggy and gave an error but ... it's a draft and you will get general idea.
    And here qStdModelExample&#46.zip is what You, in my opinion, should do, using QStandardModel and listView.

    Best luck
    What I'm going to do is to visualize several digital gates(AND, OR, XOR, .... ) based on input of the program.
    so I need to plot:
    1- several gates(pictures) in different levels.
    2- wires that connect gates.


    now I'm not sure about 2 things with "QStandardModel":
    1. possibility of drawing lines on the QListView. (I tried to draw some lines on your example, but I failed! )
    2. location of each gate. I mean is it possible to adjust position of each gate(and their distances) in plan?

    Thanks in advance,
    -------------
    * P.S: Its not a homework. Its part of research project for optimizing digital gate design.

  2. #2
    Join Date
    Apr 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: problem in drwing several images on screen

    I solved my problem with help of "qLabImg_example..zip" example. (Thanks to "Talei")
    I defined a method for ploting "gates":
    Qt Code:
    1. void MainWindow::darwAGate(int x,int y,int gate_code)
    2. {
    3. //load images:
    4. QPixmap *pixmap_nand = new QPixmap("../pix/NAND.png");
    5.  
    6. QHBoxLayout *h_layout = new QHBoxLayout();
    7. QLabel *label_tmp = new QLabel(this);
    8. label_tmp->setGeometry(x,y,gate_width_pixel,gate_height_pixel);
    9. label_tmp->setPixmap(*pixmap_nand);
    10. h_layout->addWidget( label_tmp );
    11. this->setLayout(h_layout);
    12. }
    To copy to clipboard, switch view to plain text mode 

    I thinks its possible to plot several pics by the use of dynamic memory allocation("delete" and new) if I don't want to define a separate function/method.... but I didn't try that ...


  3. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    52
    Thanked 42 Times in 42 Posts

    Default Re: problem in drwing several images on screen

    Hello,
    I checked yesterday before sleep but didn't reply due to fatigue.
    So...

    QListView allows You not only to display images the way I showed in example, it can also display grid, between each "image". Think of it as n*m matrix, or spreadsheet, it's not exactly that way, but my point here is that You can span grids. And that way you can cheat displaying connection between in/out gates. But that would require a lot of tweaking and is probably not the way to go. (Change listView to tableView in example and set same model to see the difference, maybe table is what You want after all ).
    Alternatively You could subclass one of the widget, that looks closest to Your desired widget that "holds" all the gates, then reimplement paint function, and paint image yourself. Prepare png for gates keeping in mind that in/out for each gates should be in the same position for each gate type. Then simply copy png onto screen.

    But the problem is connection between gates. So what You could do is to implement A Star (A*) algorithm (path finding) and firstly copy all gates onto screen (for A* mark this area as blocked, in row manner ), then mark output of the gate as START for A*, and proper input of another gate as END for A*. How to find position of out/in of gates? As stated before prepare accordingly png so those place will be at fixed position + png offset. Lines could be painted on anothe QPixmap so if there is a need to modification You could implement that as well (simply deleting old connection grid, and repainting new one). That way You could draw a really complex gates, not only simple one. Again that is probably not what you want due to complexity, and I assume that you have predefined png for connections as well.

    Then you could use QGraphicsView, see /qt/examples/graphicsview, especially qt/examples/graphicsview/diagramscene, for examples. I didn't do much work with this, so I can't point you any useful examples that You could use, but last example should give You general idea how to paint these pngs.

    Also I assume that program only draw gates, and don't allow any modification/correction, so, as stated before You could pull it off with QListView but I think easiest way would be going with QGraphicsView, because that allow You scrolling, zooming, etc...

    Best luck with you project
    EDIT: I forget about QPainter, that can draw shapes, lines, etc.. So you could place in table at col 0 row 1-2 gate png, at col 1 row 1-2 span and draw connections, and at col 2 row 1-2 gates pngs.
    Last edited by Talei; 30th April 2010 at 08:04.

  4. #4
    Join Date
    Apr 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: problem in drwing several images on screen

    Hello,
    I checked yesterday before sleep but didn't reply due to fatigue.
    So...

    QListView allows You not only to display images the way I showed in example, it can also display grid, between each "image". Think of it as n*m matrix, or spreadsheet, it's not exactly that way, but my point here is that You can span grids. And that way you can cheat displaying connection between in/out gates. But that would require a lot of tweaking and is probably not the way to go. (Change listView to tableView in example and set same model to see the difference, maybe table is what You want after all ).
    Alternatively You could subclass one of the widget, that looks closest to Your desired widget that "holds" all the gates, then reimplement paint function, and paint image yourself. Prepare png for gates keeping in mind that in/out for each gates should be in the same position for each gate type. Then simply copy png onto screen.

    But the problem is connection between gates. So what You could do is to implement A Star (A*) algorithm (path finding) and firstly copy all gates onto screen (for A* mark this area as blocked, in row manner ), then mark output of the gate as START for A*, and proper input of another gate as END for A*. How to find position of out/in of gates? As stated before prepare accordingly png so those place will be at fixed position + png offset. Lines could be painted on anothe QPixmap so if there is a need to modification You could implement that as well (simply deleting old connection grid, and repainting new one). That way You could draw a really complex gates, not only simple one. Again that is probably not what you want due to complexity, and I assume that you have predefined png for connections as well.

    Then you could use QGraphicsView, see /qt/examples/graphicsview, especially qt/examples/graphicsview/diagramscene, for examples. I didn't do much work with this, so I can't point you any useful examples that You could use, but last example should give You general idea how to paint these pngs.

    Also I assume that program only draw gates, and don't allow any modification/correction, so, as stated before You could pull it off with QListView but I think easiest way would be going with QGraphicsView, because that allow You scrolling, zooming, etc...

    Best luck with you project
    EDIT: I forget about QPainter, that can draw shapes, lines, etc.. So you could place in table at col 0 row 1-2 gate png, at col 1 row 1-2 span and draw connections, and at col 2 row 1-2 gates pngs.
    Alright thanks Telei !

Similar Threads

  1. Problem with Splash Screen ?
    By vinod in forum Qt Programming
    Replies: 13
    Last Post: 11th April 2020, 17:15
  2. Touch screen problem in Qtopia
    By geetha in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 12th September 2008, 07:33
  3. On Screen Keyboard Problem
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2008, 13:28
  4. Available Screen Problem
    By December in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2007, 16:01
  5. Problem with screen update...
    By mysearch05 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2006, 18:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.