Results 1 to 3 of 3

Thread: Drawing graphics, used example from KAsteroids

  1. #1
    Join Date
    May 2011
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Drawing graphics, used example from KAsteroids

    Hi all,

    I have to develop a GUI which will be deployed in an embedded system. But first i would like to develop a "simulator". The screen of the embedded system will have the GUI, and the simulator on the pc will have the GUI inserted in the system's "picture" on which the user clicks to interact.

    Since performance was a issue I chose the KASterioids example and developed from that using pixmaps whenever possible (like sprites or gifs if you want). I got the embedded GUI components and rendering fine, and now i want to insert it in the simulator. But the main problem is that I can't get the GUI to render in the transparent window of the simulator's image.... any help will be much appreciated.

    Here is the some code to understand:

    Here i try to setup the two scenes:
    Qt Code:
    1. TopLevel::TopLevel( QWidget *parent, const char *name )
    2. : Q3MainWindow( parent, name, 0 )
    3. {
    4.  
    5. LCDArea = new LCDRender(this);
    6. LCDArea->setAttribute(Qt::WA_ContentsPropagated);
    7.  
    8. KIOSKArea = new KIOSKRender(LCDArea);
    9. KIOSKArea->setAttribute(Qt::WA_ContentsPropagated);
    10.  
    11.  
    12. /* QWidget *mainWin = new QWidget(LCDArea);
    13.   mainWin->setFixedSize(681, 541);
    14.   QImage backgnd(QCoreApplication::applicationDirPath()+"/../mc_home_charge/resources/aux/bg.png");
    15.   // QPalette p(palette());
    16.   // p.setBrush(mainWin->backgroundRole(), QBrush(backgnd));
    17.   // mainWin->setPalette(p);
    18.   QPixmap pm( QCoreApplication::applicationDirPath()+"/../mc_home_charge/resources/aux/bg.png");
    19.   mainWin->setBackgroundPixmap(pm);
    20.   mainWin->setAutoFillBackground(true); */
    21.  
    22. //setBackgroundColor(Qt::black);
    23. //setBackgroundMode(Qt::NoBackground);
    24. LCDArea->setAutoFillBackground(true);
    25. setCentralWidget(LCDArea);
    26. }
    To copy to clipboard, switch view to plain text mode 
    here is the KIOSK or "physical unit"
    Qt Code:
    1. KIOSKRender::KIOSKRender( QWidget *parent, const char *name )
    2. : QWidget( parent, name ),
    3. field(0, 0, LCD_XOFFSET0+WIDTH, LCD_YOFFSET0+HEIGHT),//field(0, 0, LCD_XOFFSET0+320, LCD_YOFFSET0+240),
    4. view(&field,this)
    5. {
    6. int fontID(-1);
    7. bool fontWarningShown(false);
    8.  
    9. // Include custom font
    10. QFile res(QCoreApplication::applicationDirPath()+"/../mc_home_charge/"+customFont);
    11. // qDebug() << QCoreApplication::applicationDirPath()+"/../mc_home_charge/"+customFont;
    12. if (res.open(QIODevice::ReadOnly) == false) {
    13. if (fontWarningShown == false) {
    14. qDebug() << "Error opening custom font1";
    15. fontWarningShown = true;
    16. }
    17. } else {
    18. fontID = QFontDatabase::addApplicationFontFromData(res.readAll());
    19. if (fontID == -1 && fontWarningShown == false) {
    20. qDebug() << "Error opening custom font2";
    21. fontWarningShown = true;
    22. }
    23. }
    24.  
    25. view.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    26. view.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    27. view.setCacheMode(QGraphicsView::CacheBackground);
    28. view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    29. view.setOptimizationFlags(QGraphicsView::DontClipPainter
    30. | QGraphicsView::DontSavePainterState
    31. | QGraphicsView::DontAdjustForAntialiasing);
    32. view.viewport()->setFocusProxy( this );
    33.  
    34.  
    35. //QPixmap pm( IMG_BACKGROUND );
    36. //field.setBackgroundBrush( pm );
    37. //field.setBackgroundBrush(QBrush(Qt::black));
    38. //setBackgroundMode(Qt::NoBackground);
    39.  
    40. refreshRate = REFRESH_RATE;
    41.  
    42. initialized = readSprites();
    43. if ( !initialized ) {
    44. qDebug() << "Error reading sprites";
    45. }
    46.  
    47. bg->on();
    48.  
    49. QTimer *refresher = new QTimer(this);
    50. connect(refresher, SIGNAL(timeout()), this, SLOT(refresh()));
    51. refresher->start(1000/refreshRate);
    52. }
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Last edited by wysota; 21st May 2011 at 00:13. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drawing graphics, used example from KAsteroids

    What do you want to render where? What does KAsteroids have to do with your code? And why are you using Qt3 classes (Q3MainWindow)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2011
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: Drawing graphics, used example from KAsteroids

    Thank you wysota.

    Since I am not yet profficient with Qt I used KAsteroids code as a base to my own code, and hence the Qt3 classes which I plan to substitute once I'm sure everything is working.

    So I basically have two classes each with their own QGraphicsScene and QGraphicsView. What I want to do is design two objects, one with a central console or GUI, and another with the simulator or physical UI, which will have the graphical characteristic of being like a photoframe i.e, with transparency near the center. But the problem it that i can't get the GUI to show through the UI's transparency.

    Cheers

Similar Threads

  1. Qt Graphics
    By soumya in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2009, 09:41
  2. Qt Graphics
    By soumya in forum Qt Programming
    Replies: 8
    Last Post: 19th August 2009, 12:12
  3. Graphics View: Drawing Items that don't scale
    By Disperato in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2009, 17:16
  4. Replies: 4
    Last Post: 14th April 2008, 16:39
  5. Qt graphics
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 22nd May 2007, 06:20

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.