PDA

View Full Version : QDockWidget, QCleanlooksStyle and QWindowsVistaStyle



daleotar
22nd June 2011, 11:14
Hi.

I have a MainWindow with some QDockWidgets, nothing special.
I'm applying to the entire QApplication a style sub-classed from QCleanlooksStyle just for changing some features like icon sizes and stuff...

However I've noticed that QDockArea "hightlights" (with a blue color) when QDockWidget are near to be placed with QWindowsVistaStyle or QWindowsXPStyle... With any other style the "hightlight" just consists of a dotted frame instead of a colored frame...I don't know how to implement that kind of "highlighting" with any other style like QCleanlooksStyle or QPlastiqueStyle... If anyone knows how to do it I would appreciate that give me some directions to do that...

I suppose that is something maybe with styleSheet or styles or mousemoveevent or something... maybe easier...

Below you'll find what is the difference and what I'm talking about...

Thanks and sorry for my english...

Santosh Reddy
23rd June 2011, 06:20
It may not be possible, as QDockWidget supports styling of the title bar and the title bar buttons when docked.

Also the Documentation says

The style sheet has no effect when the QDockWidget is undocked as Qt uses native top level windows when undocked

daleotar
24th June 2011, 03:07
Thanks for the reply Santosh.

I know that only QDockWidget's title bar and title bar buttons are customizable but I think that this is more something about the QDockArea than QDockWidget indeed and also I know that the window containing a QDockWidget is a native operating system window. I don't know if someone knows a "Qt Troll" or one of the Qt developers who maybe knows about this kind of topics because I think this is more about setting up the subclassed style than the operating system...

Santosh Reddy
24th June 2011, 06:30
Ok daleotar, here is something which I can say, It is possible to change the color of the QDockArea "hightlights" to what every you want, but still I don't think it is possible using style sheets (not directly)

One of the ways to do it is, by sub-classing and implementing the same behavior irrespective of style, hmm.. wait a minute, may be you can try sub-classing and apply style sheet on the sub-class, or what ever you like, but here is how to do it.

QMainWindow has internal layout which manages all the QToolBar, QDockWidgets etc in the main window, and allow the user to move around and play with layout. So during the moving of the layout widgets, the main window layout (i.e. QMainWindowLayout, which is private to QMainWindow), uses QRubberBand to highlight the allowed docking region.

So what you can do is, replace the QRubberBand with a custom MyRubberBand, and do what ever you want in custom MyRubberBand. This may not be straight forward, as you need to access a QMainWindow's private variable, but I can suggest a way to do so, here it is



// Private Classes are not visible by including <QMainWindow>, so this is required. check the path on you platform
#include "../../src/gui/widgets/qmainwindowlayout_p.h"

class MyRubberBand : public QRubberBand
{
public:
MyRubberBand(Shape s, QWidget * p = 0) : QRubberBand( s, p ) {
QPalette palette;
palette.setBrush( QPalette::WindowText, QBrush( Qt::red ) );
setPalette(palette);
}

protected:
virtual void paintEvent( QPaintEvent * ) {
QStylePainter painter(this);

QStyleOptionFocusRect option;
option.initFrom( this );

painter.drawControl(QStyle::CE_FocusFrame, option);
}
};

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
Ui::MainWindow()
{
setupUi(this);
...
QMainWindowLayout * main_layout = dynamic_cast<QMainWindowLayout *>(layout());
if(main_layout)
{
delete main_layout->gapIndicator; //gapIndicator is QRubberBand, just delete it and replace it your rubber band
main_layout->gapIndicator = new MyRubberBand(QRubberBand::Rectangle, this);
}
...
}


Also refer this post for QRubberBand style
http://www.qtcentre.org/threads/21324-How-to-draw-QRubberBand-with-red-color

daleotar
25th June 2011, 02:36
Thanks Santosh, It was really helpful. As soon as I got it working I'll post it just for information of the other users