[Qt-interest] Customized QWidget item not visible on QMainWindow(now QWidget)
varun singh
mailthatmale at yahoo.co.in
Wed Aug 5 17:54:11 CEST 2009
hi,
Well Andreas i tried what you suggested, but it's still not visible.
i appreciate your help Andreas, thanx.
I've replaced QMainWindow with QWidget to get rid of CentralWidget Concept (QMainWindow requires a Central Widget to work).
Here is another trick i did. I set the ToolTip of my Tank object n then ran the Application. And when i hovered over the set co-ordinate, it showed the tooltip, it means the object is present there but still somehow not visible (i've tried setVisible and show() functions).
Still seeking for help...
-Varun
>
> Message: 1
> Date: Tue, 4 Aug 2009 17:16:31 +0200
> From: "Andreas Diehl" <Andreas_Diehl at abs.org>
> Subject: Re: [Qt-interest] Customized QWidget item not
> visible on
> QMainWindow
> To: <qt-interest at trolltech.com>
> Message-ID: <CA9DB32D4785A74899C9DED210D4969383E479 at exmail.abs.org>
> Content-Type: text/plain;
> charset="iso-8859-1"
>
> Hello Varun.
> Of course you've found the solution already: Create a new
> widget and set it as the central widget of your QMainWindow
> and attach your tanks to it:
>
> MainWindow::MainWindow(QWidget *parent)
> : QMainWindow(parent)
> {
> this->setGeometry(100, 100, 1250, 650);
> QWidget* battlefield = new QWidget(this);
> this->setCentralWidget(battlefield);
>
> mTank = new Tanks(QPoint(200, 200), battlefield);
> }
>
> Regards,
> Andreas
>
>
> -----Urspr?ngliche Nachricht-----
> Von: qt-interest-bounces at trolltech.com
> [mailto:qt-interest-bounces at trolltech.com]
> Im Auftrag von varun singh
> Gesendet: Dienstag, 4. August 2009 16:51
> An: qt-interest at trolltech.com
> Betreff: Re: [Qt-interest] Customized QWidget item not
> visible on QMainWindow
>
>
> hi,
>
> Well i tried mTank->show(), but it didnt work, and also
> as Ender told painter.begin() is not going to work.
> But anyways, thanx Donal and _h_, i appreciate your
> concern, thanx to Ender too.
>
> Well, while wandering around my code, i tried
> MainWindow::setCentralWidget(mTank), and it was visible. The
> problem is not solved but I think that gives some clue. I'm
> working on it. But if i can get some imputs from the
> members, that would be great help.
>
> -Varun
> ------------------
> >
> > Hi,
> > Well i'm finding this one a bit difficult though
> it sounds simple.
> > I'm
> making a game named Tanks (in which the tanks will fight).
> >
> > So, i subclassed QWidget and made a function to create
> a tank like
> > figure
> (using rectangles) with the help of QWidget::paintEvent().
> Then i initialized a Tank variable in QMainWindow class.
> >
> > Now, the MainWindow runs, but shows blank.
> > Here's a snapshot of the code.
> >
> ******************************************************************************
> >
> > Tanks::Tanks(QPoint point, QWidget *parent)
> > :QWidget(parent)
> > {
> > mPosition = point;
> > this->setGeometry(mPosition.x() - 25,
> mPosition.y() - 25, 50, 50);
> >
> this->setSizePolicy(QSizePolicy::Maximum,
> QSizePolicy::Maximum);
> >
> > /* mBody, mBarrel etc. are members of
> type QRect*/
> > mBody = QRect(mPosition.x() - 15,
> mPosition.y() - 15, 30, 30);
> > mBarrel = QRect(mPosition.x() ,
> mPosition.y(), 30, 4);
> > mWheelTop = QRect(mPosition.x() - 20,
> mPosition.y() - 20, 40, 10);
> > mWheelBottom = QRect(mPosition.x() - 20,
> mPosition.y() + 10, 40, 10);
> > update();
> > }
> >
> > void Tanks::paintEvent(QPaintEvent *event) {
> > QPainter painter(this);
> > paintTank(painter);
> >
> > }
> >
> > void Tanks::paintTank(QPainter &painter) {
> > paintBody(painter);
> > paintBarrel(painter);
> > paintWheels(painter);
> > }
> >
> >
> > void Tanks::paintBody(QPainter &painter)
> > {
> > painter.drawRect(mBody);
> >
> > }
> >
> > void Tanks::paintBarrel(QPainter &painter)
> > {
> > painter.drawRect(mBarrel);
> > }
> >
> > void Tanks::paintWheels(QPainter &painter)
> > {
> > painter.drawRect(mWheelTop);
> > painter.drawRect(mWheelBottom);
> > }
> >
> > -----------------
> > /*Snippet of QMainWindow*/
> > MainWindow::MainWindow(QWidget *parent)
> > : QMainWindow(parent)
> > {
> > this->setGeometry(100, 100, 1250,
> 650);
> > mTank = new Tanks(QPoint(200, 200),
> this);
> > }
> >
> >
> *******************************************************************************
> > Can anyone help?
> >
> > -Varun
>
Yahoo! recommends that you upgrade to the new and safer Internet Explorer 8. http://downloads.yahoo.com/in/internetexplorer/
More information about the Qt-interest-old
mailing list