Results 1 to 4 of 4

Thread: Simple and silly question about QWidget

  1. #1
    Join Date
    Mar 2009
    Location
    Israel
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Simple and silly question about QWidget

    I have default application CTest based on QMainWindow.

    If I add Qt class dirive from QWidget , do I have to add also UI file for that class ????????????
    //Code Not working CTest inherite QWidget

    Qt Code:
    1. #include "test3.h"
    2. #include <QWidget>
    3. #include "CTest.h"
    4. test3::test3(QWidget *parent, Qt::WFlags flags)
    5. : QMainWindow(parent, flags)
    6. {
    7. ui.setupUi(this);
    8.  
    9. m_pT = new CTest(ui.centralWidget);
    10. m_pT->setStyleSheet("QWidget { background-color: blue; }");
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //Code working
    2. #include "test3.h"
    3. #include <QWidget>
    4. test3::test3(QWidget *parent, Qt::WFlags flags)
    5. : QMainWindow(parent, flags)
    6. {
    7. ui.setupUi(this);
    8.  
    9. QWidget* pT = new QWidget(ui.centralWidget);
    10. pT->setStyleSheet("QWidget { background-color: blue; }");
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by dima; 2nd December 2010 at 10:25.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Simple and silly question about QWidget

    Just post the code please, its easy to misunderstand your explanation.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    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: Simple and silly question about QWidget

    If you reimplemented the paintEvent for the CTest class then stylesheets won't work, they only work with default widgets as the drawing goes through the style then. Instead of stylesheets you can always use QPalette.
    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.


  4. #4
    Join Date
    Mar 2009
    Location
    Israel
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simple and silly question about QWidget

    I didn't reimplemented anything , I just added new class to project that derive QWidget , with no more extra code lines.

Similar Threads

  1. simple question
    By assismvla in forum Newbie
    Replies: 5
    Last Post: 30th May 2010, 23:30
  2. Replies: 0
    Last Post: 8th July 2009, 11:01
  3. simple MVC question!
    By landonmkelsey in forum Qt Programming
    Replies: 14
    Last Post: 19th August 2008, 12:25
  4. A simple question
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 6th April 2007, 08:54
  5. Another simple question...
    By Dark_Tower in forum Newbie
    Replies: 5
    Last Post: 31st March 2006, 16:13

Tags for this Thread

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.