PDA

View Full Version : how can i customize a QMainWindow



wygggyxtf
22nd June 2007, 10:00
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?

high_flyer
22nd June 2007, 10:09
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.

wygggyxtf
22nd June 2007, 10:40
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!

high_flyer
22nd June 2007, 10:56
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?

wygggyxtf
22nd June 2007, 11:12
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.

guilugi
22nd June 2007, 11:16
setMouseTracking(true) should do the trick.
With this, MainWindow will receive mouse events even if no buttons are being pressed.

wygggyxtf
22nd June 2007, 11:26
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?

high_flyer
22nd June 2007, 11:35
this is getting to specific.
We need to see ALL the relevant code.

wygggyxtf
22nd June 2007, 12:03
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::DockTop);
this->moveDockWindow(myDockWidget,Qt::DockTop);

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!

high_flyer
22nd June 2007, 12:13
and the mouseMoveEvent()?

wygggyxtf
22nd June 2007, 12:20
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!

high_flyer
22nd June 2007, 12:30
and what is the behaviour? are you getting no message box at all?

wygggyxtf
22nd June 2007, 12:41
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".

high_flyer
22nd June 2007, 12:49
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?

wygggyxtf
23rd June 2007, 02:32
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!

pakulo
23rd June 2007, 07:18
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");