Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User timohan's Avatar
    Join Date
    Mar 2012
    Posts
    4
    Hi,

    I try skin QCombobox's border with custom pictures.
    The problem comes that it seems QCombobox's list view popup have somekind background drawing on drop list.

    For example:
    I have own custom combobox, and I try set border radius via style sheet.
    ----------------
    CComboBox::CComboBox(QWidget *parent) : QComboBox(parent)
    {
    QString strStyle = "QComboBox QAbstractItemView { background-image: none; background: transparent; border: 3px solid darkgray; selection-background-color: red; border-top-right-radius: 13px; border-bottom-right-radius: 13px; border-bottom-left-radius: 13px; border-top-left-radius: 13px; };";

    setStyleSheet(strStyle);
    }
    ------------
    This doesn't actually work, because it still does draw something square behind it. and I am trying to understand what is that behind the list popup....

    and how can I remove or change that popup's drawing behind the popup list view.

    Here is the problem with that stylesheet in picture, so you can see the square in popup listbox behind radius:
    http://www.timogames.com/test/combobox_popup.png
    Last edited by timohan; 2012-03-22 at 11:31.

  2. #2
    Nokia Developer Moderator gnuton's Avatar
    Join Date
    Mar 2009
    Posts
    1,024
    Hi,
    The "square" drawn behind the ComboBox list is a Dialog.
    I guess that list needs the Qt::WA_TranslucentBackground attribute set with QWidget::setAttribute().

  3. #3
    Registered User timohan's Avatar
    Join Date
    Mar 2012
    Posts
    4
    As I understand, it's QFrame that is WindowFlag WS:Popup.....

    I have tried:
    CComboBox::CComboBox(QWidget *parent) : QComboBox(parent)
    {
    view()->parentWidget()->setAttribute(Qt::WA_TranslucentBackground);
    view()->parentWidget()->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
    }
    But it does still draw a shadow.
    ------ I can set shadow off (but then it stops being popup and stops following the application & combobox)
    CComboBox::CComboBox(QWidget *parent) : QComboBox(parent)
    {
    view()->parentWidget()->setAttribute(Qt::WA_TranslucentBackground);
    view()->parentWidget()->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    }
    (this is way, no shadow, but then it's wrong other way).
    -----------
    Also:
    view()->parentWidget()->setWindowFlags(Qt::Popup | Qt::Window | Qt::FramelessWindowHint);
    doesn't help....
    -----------

  4. #4
    Nokia Developer Moderator gnuton's Avatar
    Join Date
    Mar 2009
    Posts
    1,024
    Well, it could be a QFrame or whatever. The important thing as you said is the WA.

    view()->parentWidget()->setWindowFlags(Qt::Popup | Qt::Window | Qt::FramelessWindowHint); doesn't really help because Qt::Popup is already a Qt::Window.
    IIRC if you look inside the Qt code (QtGUI Module) you will find out that Qt::Popup is basically Qt::Popup | Qt::Window.

    The point here is that Windows attributes behave in different ways according to the window manager of your desktop system,
    and you need just few of behaviour which are given to Qt::Popup on windows.

    To forget about WM relates issue there is a simple way, but I don't know if can be valid for your case.
    Basically you can embedd your widget inside a QGraphicsView through a QGraphicsViewProxy.
    This way you don't need to set WAs and I believe your stylesheet should work correctly.

  5. #5
    Registered User timohan's Avatar
    Join Date
    Mar 2012
    Posts
    4
    You mean, like this?
    ----
    CComboBox::CComboBox(QWidget *parent) : QComboBox(parent)
    {
    QGraphicsScene *scene = new QGraphicsScene();
    QGraphicsProxyWidget *proxy = scene->addWidget( view()->parentWidget() );
    QGraphicsView *view1 = new QGraphicsView(scene);
    }
    ---
    This doesn't work at all. I am not very good using QGraphicsView.

    if I use: view1->show();
    it does create additional dialog, and drop list box appears on it, but it doesn't work at all as it should be.

  6. #6
    Nokia Developer Moderator gnuton's Avatar
    Join Date
    Mar 2009
    Posts
    1,024
    Hi,
    the graphicsview is a QWidget. If you instantiate it with
    QGraphicsView *view1 = new QGraphicsView(scene),

    you basically create a new dialog since the graphicsview doesn't have any parent.

    Having a new top level widget is actaully the thing you want to avoid; and this is something you can do using a GraphicsView.
    You may create the GraphicsView as child of your MainWindow. In this case, the GraphicsView should be transparent and cover the entire app.
    This about it as a simple transparent canvas where you can draw your widget.
    Then you can draw the popup list inside the graphics view.

    For sure this is an hack. The right and clean way to do what you are trying to so is to use these methods
    setAttribute(Qt::WA_TranslucentBackground);
    setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

    but you said they lead to some other problems, which you have not actually described.
    Feel free to detail more about this issue or just ask more if get stuck with implementation of the graphics view way.

  7. #7
    Registered User timohan's Avatar
    Join Date
    Mar 2012
    Posts
    4
    I have also tried:
    QGraphicsView *view1 = new QGraphicsView(scene, view()->parentWidget()->parentWidget());
    or:
    QGraphicsView *view1 = new QGraphicsView(scene, view()->parentWidget());
    But it doesn't help either. popup appears for second and then disappears somewhere.
    -----------
    I also noted another problem.
    Making stylesheet border + radius corner, does mess up with scrollbars, and stylesheet's border (radius) doesn't appear if scrollbar is active on listbox's corner areas. it's ok only if listbox doesn't have scrollbar.
    -----------
    Could you give more code specific help. I have tried many ways, but I just cannot get shadow disappear correctly. Note that QFrame "dialog" should be WS:POPUP it and it does cause the shadow drawing, otherwise it doesn't sync with combobox.

Similar Threads

  1. Background color and border-radius
    By Rondo23 in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-11-28, 10:31
  2. drop down list
    By vrnreddy84 in forum Symbian C++
    Replies: 5
    Last Post: 2009-08-25, 13:39
  3. how to put the values in drop down list?
    By sudheer.skt in forum Symbian C++
    Replies: 1
    Last Post: 2008-04-11, 13:14
  4. cutom list box to popup list??
    By harish13_ks in forum Symbian C++
    Replies: 5
    Last Post: 2007-10-06, 12:06
  5. Popup list/Choice from list
    By brianpegan in forum Mobile Java General
    Replies: 0
    Last Post: 2004-03-18, 11:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved