[Qt] QApplicationH and QApplication_setStyleSheet
zeljko
zeljko at holobit.net
Sun Nov 8 09:51:46 CET 2009
On Saturday 07 November 2009 22:18, Marcin Dębicki wrote:
> Ok, now I have another problem regarding styles (less Qt bindings itself).
> I have listbox with Style set to lbOwnerDrawFixed and following procedure
> to draw item:
1. You should check Qt issues with stylesheets and QAbstractItemViews (eg.
QListView, QTreeWidget etc...).
2. I think if U use stylesheets, that you cannot paint that parts as you want,
so try without your paint procedure.
> var
> Bitmap: TBitmap; { temporary variable for the
> itemÄ‚Ë€â„Ës bitmap }
> Offset: Integer; { text offset width }
> s: string;
> Pc: string;
> begin
> try
> with lbPlaylist.Canvas do { draw on control canvas, not on the form }
> begin
> // FillRect(TxtRect); { clear the rectangle }
> Offset := 2;
> lbPlaylist.Canvas.AutoRedraw:=true; { provide default offset }
> Bitmap := TBitmap(lbPlaylist.Items.Objects[Index]); { get the bitmap }
> if Bitmap <> nil then
>
> begin
> Draw(ARect.Left + Offset, ARect.Top, Bitmap); {render bitmap}
> Offset := Bitmap.width + 6; { add four pixels between bitmap and
> text}
> end;
> if (not Self.FStopped) and (Index=CurrentIndex)and
> (Playlist.GetItem(CurrentIndex)^.FileName=CurrentFile) then
> Font.Style:=Font.Style+[fsBold] else
> Font.Style:=Font.Style-[fsBold];
>
> StrPCopy(Pc, Self.Playlist.GetItem(Index)^.FileName);
> if not IsStream(Pc) then
> s:=ProduceFormatedString(KSPMainWindow.FormatedPlayListInfo,
> Self.Playlist.GetItem(Index)^.Tag,
> GetDuration(Self.Playlist.GetItem(Index)^.Stream),
> Index+1) else begin
> if (KSPMainWindow.CurrentIndex=Index) and
> (Player.StreamInfo.Title<>'') then
> s:=Format(SShoutcastEntry, [Player.StreamInfo.Title]) else
> s:=Format(SShoutcastEntry, [Self.Playlist.GetItem(Index)^.FileName]);
> end;
> TextOut(ARect.Left + Offset, ARect.Top, s);//lbPlaylist.Items[Index]) {
> display the text }
> end;
> finally
>
> end;
>
> The style used by me is:
>
> QTextEdit, QListView {
> background-color: rgb(195, 195, 195);
> color: rgb(195, 195, 195);
> background-attachment: fixed;
> }
>
> QListView {
> show-decoration-selected: 1; /* make the selection span the entire
> width of the view */
> }
>
> QListView::item {
> background: #EEEEEE;
> }
>
> QListView::item:selected {
> border: 1px solid #6a6ea9;
> }
>
> QListView::item:selected:!active {
> background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
> stop: 0 #ABAFE5, stop: 1 #8588B2);
> }
>
> QListView::item:selected:active {
> background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
> stop: 0 #6a6ea9, stop: 1 #888dd9);
> }
>
> QListView::item:hover {
> background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
> stop: 0 #FAFBFE, stop: 1 #DCDEF1);
> }
>
> Problem is that background itself is painted properly everywhere except
> where text goes. The same is about font.
>
> 2009/11/7 zeljko <zeljko at holobit.net>
>
> > On Friday 06 November 2009 20:07, Marcin Dębicki wrote:
> > > Probably stupid questions but I can't really find an answer.
> > >
> > > 1. How can I retrieve handle for my application so I can use
> > > QApplication_setStyleSheet? Application is created visually with
> > > Lazarus.
> >
> > QAppllication_setStyleSheet(QCoreApplication_instance(), @WStr) where
> > WStr is
> > widestring which contains stylesheet code.
> >
> > > 2. Second parameter for QApplication_setStyleSheet is stylesheet code,
> > > right? For example:
> > >
> > > QMainWindow::separator {
> > > background: yellow;
> > > width: 10px; /* when vertical */
> > > height: 10px; /* when horizontal */
> > > }
> > >
> > > QMainWindow::separator:hover {
> > > background: red;
> > > }
> > >
> > > Best regards,
> > > Marcin Dębicki
> >
> > _______________________________________________
> > Qt mailing list
> > Qt at lists.lazarus.freepascal.org
> > http://lists.lazarus.freepascal.org/mailman/listinfo/qt
More information about the Qt
mailing list