Results 1 to 16 of 16

Thread: how can i customize a QMainWindow

  1. #1
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1

    Default how can i customize a QMainWindow

    hello:
    I want to change the title bar and border of a QMainWindow. for example: i want to paint a picture on the title bar .But QPainter can not paint any thing on title bar. if somebody can help me? how can i do?
    Last edited by wygggyxtf; 22nd June 2007 at 09:29.

  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: how can i customize q QMainWindow

    I have inplmented a cuntomized title bar by removing the window decorations, and using my own widget as a titlebar.
    I don't think it is possible to actually change the title bar it self, but maybe someone else knows better.
    ==========================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
    Jun 2007
    Posts
    8
    Thanks
    1

    Default Re: how can i customize q QMainWindow

    Quote Originally Posted by high_flyer View Post
    I have inplmented a cuntomized title bar by removing the window decorations, and using my own widget as a titlebar.
    I don't think it is possible to actually change the title bar it self, but maybe someone else knows better.

    yes, I have tried this method,but some task trouble me. without real title bar and border, how can i move and resize the QMainWindow with mouse. when i move my mouse to the edge of the QMainwindow, the shape of mouse didn't change to double-arrowhead, so i can not resie the QMainWindow. please tell me , how did you resove the trouble. had better , put up your code to me. please!

  4. #4
    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: how can i customize a QMainWindow

    without real title bar and border, how can i move and resize the QMainWindow with mouse.when i move my mouse to the edge of the QMainwindow, the shape of mouse didn't change to double-arrowhead, so i can not resie the QMainWindow.
    You have to implement it your self of coucrse (that is what I did).
    please tell me , how did you resove the trouble. had better , put up your code to me. please!
    Ah.. sorry, not at the moment, no time to look for it (I am at work). (maybe tonight when I get home)
    But where is the probem?
    You just catch the mouse events, and in them do the moving and resizing, where is the problem?
    ==========================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.

  5. #5
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1

    Default Re: how can i customize a QMainWindow

    The probem is : I can not cath some mouse events, for example: i can not catch mouse move event, although qt have a mouseMoveEvent() slot, but this is be called only when mouse move over the QMainwindow and a mouse key is pressed. if no mouse is pressed, this function is will not be called.
    on the other hand, i do not know how to caculate the size of QMainwindow.
    please excuse me,I am new to qt, i know only a few qt knowledge. if OK ,please put up your code to me when you are free.

  6. #6
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how can i customize a QMainWindow

    setMouseTracking(true) should do the trick.
    With this, MainWindow will receive mouse events even if no buttons are being pressed.

  7. #7
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1

    Default Re: how can i customize a QMainWindow

    Quote Originally Posted by guilugi View Post
    setMouseTracking(true) should do the trick.
    With this, MainWindow will receive mouse events even if no buttons are being pressed.
    I have tried this method, but it's no effect.
    i wirte "this->setMouseTracking(true);" in the constructor.
    if i write the code at a wrong position? please tell me?

  8. #8
    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: how can i customize a QMainWindow

    this is getting to specific.
    We need to see ALL the relevant code.
    ==========================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.

  9. #9
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1

    Default Re: how can i customize a QMainWindow

    Quote Originally Posted by high_flyer View Post
    this is getting to specific.
    We need to see ALL the relevant code.
    this->setMouseTracking(true);
    Q3DockWindow * myDockWidget=new Q3DockWindow(this);
    QLabel * myTitle = new QLabel(myDockWidget);
    myTitle->setText("hello this is my Title bar");
    myDockWidget->setWidget(myTitle);
    this->addDockWindow(myDockWidget,Qt:ockTop);
    this->moveDockWindow(myDockWidget,Qt:ockTop);

    QTabWidget * myTb = new QTabWidget(this);

    myPixMap.loadFromData(contact_png,sizeof(contact_p ng),"PNG");
    QIcon myContactIcon(myPixMap);
    myTb->addTab(cvlist,myContactIcon,NULL);

    myPixMap.loadFromData(treasure_png,sizeof(treasure _png),"PNG");
    QIcon myTreasureIcon(myPixMap);

    QAxWidget * object = new QAxWidget("8856F961-340A-11D0-A96B-00C04FD705A2");

    object->dynamicCall("Navigate(const QString&)",treasureWebSite);
    myTb->addTab(object,myTreasureIcon,NULL);

    myPixMap.loadFromData(friend_png,sizeof(friend_png ),"PNG");
    QIcon myFriendIcon(myPixMap);
    QAxWidget * object1 = new QAxWidget("8856F961-340A-11D0-A96B-00C04FD705A2");
    object1->dynamicCall("Navigate(const QString&)",friendWebSite);
    myTb->addTab(object1,myFriendIcon,NULL);
    myTb->setIconSize(QSize(18,20));

    myTb->setTabPosition ( QTabWidget::West);
    myUserInfoButton.setIcon(PsiIconset::instance()->statusPtr(STATUS_OFFLINE)->pixmap());
    myUserInfoButton.setText(" ");
    d->vb_main->addWidget(&myUserInfoButton);
    d->vb_main->addWidget(myTb);


    this is the relevant code, please check up, if some thing wrong with the code!

  10. #10
    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: how can i customize a QMainWindow

    and the mouseMoveEvent()?
    ==========================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.

  11. #11
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1

    Default Re: how can i customize a QMainWindow

    Quote Originally Posted by high_flyer View Post
    and the mouseMoveEvent()?
    void MainWin::mouseMoveEvent ( QMouseEvent * event ){

    if(this->hasMouseTracking()){
    QMessageBox myMB1;
    myMB1.setText("hasMouseTracking");
    myMB1.exec();
    }else{
    QMessageBox myMB1;
    myMB1.setText("has no hasMouseTracking");
    myMB1.exec();

    }
    return;
    }

    this is mouseMoveEvent function!

  12. #12
    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: how can i customize a QMainWindow

    and what is the behaviour? are you getting no message box at all?
    ==========================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.

  13. #13
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1

    Default Re: how can i customize a QMainWindow

    Quote Originally Posted by high_flyer View Post
    and what is the behaviour? are you getting no message box at all?
    i move my mouse over the window, no messagebox display, then i move my mouse over the winodw and pressed a mouse key, a messagebox displayed, it say:"hasMouseTracking".

  14. #14
    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: how can i customize a QMainWindow

    hmm... strange.
    I can't explain that behaviour from what I see...

    EDIT:
    Wait, this is a main window right?
    So it might be that you have to set the mouse tracking on each element of the main widnow...
    What do you have on your main window when you run this?
    Last edited by high_flyer; 22nd June 2007 at 11:55.
    ==========================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.

  15. The following user says thank you to high_flyer for this useful post:

    wygggyxtf (23rd June 2007)

  16. #15
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1

    Default Re: how can i customize a QMainWindow

    Quote Originally Posted by high_flyer View Post
    hmm... strange.
    I can't explain that behaviour from what I see...

    EDIT:
    Wait, this is a main window right?
    So it might be that you have to set the mouse tracking on each element of the main widnow...
    What do you have on your main window when you run this?
    I have resove the trouble, above the code i have put up, there is a paragraph:
    QWidget *center = new QWidget (this, "Central widget");
    setCentralWidget ( center );

    d->vb_main = new QVBoxLayout(center);
    cvlist = new ContactView(center);

    now i add a sentence:
    center->setMouseTracking(true);

    that's OK!

    please put up your code that you customize QMainWindow to me! thanks!

  17. #16
    Join Date
    May 2007
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how can i customize a QMainWindow

    Try create message box
    QMessageBox *myMB1 = new QMessageBox(...);
    myMB1->show(); (exec())

    or change something on your widget to see work mousemove or not!
    example
    QLabel *label;
    in your constructor
    label = new QLabel ("ddd");
    label->setGeometry(...);

    and in mouseevent
    label->setCaption("Work");

Similar Threads

  1. QMainWindow modal from non-qt window?
    By hickscorp in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2008, 09:10
  2. QMainWindow resize problem
    By edb in forum Qt Programming
    Replies: 5
    Last Post: 12th January 2007, 10:31
  3. QMainWindow not receiving QResizeEvent
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 06:11
  4. Dynamically Loading a QMainWindow?
    By natron in forum Newbie
    Replies: 10
    Last Post: 21st July 2006, 01:15
  5. Replies: 18
    Last Post: 22nd February 2006, 20:51

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.