Results 1 to 4 of 4

Thread: Promote Qwidget problem

  1. #1
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Promote Qwidget problem

    Hello,

    I'm using qt creator 2.4.1, Qt 4.8 on Ubuntu 10.10.
    I need to make a background image resizable for a Qwidget, for the main QWidget i override resizeEvent in the generated file(widget.cpp) and it works fine, now i want to put inside my main QWidget another QWidget and give it a resizable background image as well so i found out the promoting to buid my custom widget (ZoneSup is just a QWidget where i override resizeEvent) .

    my custom widget :

    Qt Code:
    1. #ifndef ZONESUP_H
    2. #define ZONESUP_H
    3.  
    4. #include <QFrame>
    5. #include <QDebug>
    6. #include <QResizeEvent>
    7. #include <QPixmap>
    8. #include <QPalette>
    9.  
    10.  
    11. class ZoneSup : public QWidget
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. ZoneSup(QWidget *parent = 0);
    17.  
    18. protected:
    19. void resizeEvent(QResizeEvent *); // virtual};
    20. };
    21. #endif // ZONESUP_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "zonesup.h"
    2.  
    3. ZoneSup::ZoneSup(QWidget *parent) : QWidget(parent){
    4.  
    5. }
    6.  
    7. void ZoneSup::resizeEvent ( QResizeEvent * event )
    8. {
    9. qDebug() << "ZoneSup::resizeEvent " << event->size().width() << " ," << event->size().height();
    10.  
    11. QPalette palet = palette();
    12. QPixmap backGroundPicture(":/image/bg1.jpg");
    13. QPixmap pixmapBackGround(backGroundPicture.scaled(event->size()));
    14.  
    15. palet.setBrush(QPalette::Background, pixmapBackGround);
    16. setPalette(palet);
    17. }
    To copy to clipboard, switch view to plain text mode 

    resizevent is called but the background image is not shown.
    the same code used for the main QWidget works fine.
    I have no error and no warning.

    Thanks in advance

  2. #2
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: Promote Qwidget problem

    i'm a beginner in Qt and i can't find a way to debug this problem, i'll try to make my problem more clear so maybe someone out there will help me,

    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading UI file 'widget.ui'
    3. **
    4. ** Created: Mon Apr 16 22:29:26 2012
    5. ** by: Qt User Interface Compiler version 4.8.0
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_WIDGET_H
    11. #define UI_WIDGET_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QHeaderView>
    18. #include <QtGui/QWidget>
    19. #include "zonesup.h"
    20.  
    21. QT_BEGIN_NAMESPACE
    22.  
    23. class Ui_Widget
    24. {
    25. public:
    26. ZoneSup *resizableWidgetWithBG;
    27.  
    28. void setupUi(QWidget *Widget)
    29. {
    30. if (Widget->objectName().isEmpty())
    31. Widget->setObjectName(QString::fromUtf8("Widget"));
    32. Widget->resize(754, 531);
    33. Widget->setWindowOpacity(1);
    34. resizableWidgetWithBG = new ZoneSup(Widget);
    35. resizableWidgetWithBG->setObjectName(QString::fromUtf8("resizableWidgetWithBG"));
    36. resizableWidgetWithBG->setGeometry(QRect(150, 90, 221, 191));
    37. resizableWidgetWithBG->setMaximumSize(QSize(221, 191));
    38.  
    39. retranslateUi(Widget);
    40.  
    41. QMetaObject::connectSlotsByName(Widget);
    42. } // setupUi
    43.  
    44. void retranslateUi(QWidget *Widget)
    45. {
    46. Widget->setWindowTitle(QApplication::translate("Widget", "Widget", 0, QApplication::UnicodeUTF8));
    47. } // retranslateUi
    48.  
    49. };
    50.  
    51. namespace Ui {
    52. class Widget: public Ui_Widget {};
    53. } // namespace Ui
    54.  
    55. QT_END_NAMESPACE
    56.  
    57. #endif // UI_WIDGET_H
    To copy to clipboard, switch view to plain text mode 

    a background is not working, can i try to paint something else instead ? is it a way to find out the problem?

    Any idea is welcome, Best Regards

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Promote Qwidget problem

    From the enum QPalette::ColorRole docs:
    QPalette::Background Window This value is obsolete. Use Window instead.
    So try that first.

    QWidget::setAutoFillBackground() on the child widget straightens this out for me in a quick test. (I don't know if that is the "right" way to achieve this).

    Also, when you resize the parent window the child widget resizeEvent() fires before the parent widget resizeEvent() on my test program. The parent widget background may be be overwriting the child background before they are repainted.

  4. The following user says thank you to ChrisW67 for this useful post:

    oswalidos (17th April 2012)

  5. #4
    Join Date
    Mar 2009
    Location
    Tunisia
    Posts
    38
    Thanks
    12
    Platforms
    Windows

    Default Re: Promote Qwidget problem

    Thank you so much, QWidget::setAutoFillBackground() solved my problem, besides, in my project, parent widget resizeEvent fires before the child widget resizeEvent, and this is exactly what i need, so based on the new size of my parent window i'll resize the child window (or let the layout resize it if possible).

Similar Threads

  1. Promote to ..
    By fantom in forum Qwt
    Replies: 1
    Last Post: 11th March 2011, 10:02
  2. Replies: 18
    Last Post: 9th February 2011, 14:54
  3. Promote Qwidget problem, class already exists ???
    By tonnot in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2011, 13:10
  4. Replies: 4
    Last Post: 27th October 2010, 16:43
  5. promote to...
    By uygar in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2007, 09:07

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.