[Solved] Qt Main Window resize problem (Linux/Ubuntu 11.04, Gnome)

  • I'm in the process of porting my Qt application from Windows to Linux and I've encountered the following problem:
    Whenever I resize the window to anything greater than what it was at startup, it just shows the extra areas in grey (making it small and then normal again works though). What is visible looks the way it should (for the bigger size). I use a custom widget with the following paintEvent function:
    void StartWidget::paintEvent(QPaintEvent *e)
    QRect dRect = e->rect();
    QPainter p(this);
    QLinearGradient grad(dRect.topRight(), dRect.topLeft());
    QColor c = Qt::lightGray;
    grad.setColorAt(0, Qt::lightGray);
    p.fillRect(QRect(0,0, dRect.width(), dRect.height()), grad);
    It worked on Windows, but not on Linux (Ubuntu 11.04). Any thoughts?

    EDIT: Screenshots:
    !http://img64.imageshack.us/img64/2199/hephaistosv30001.png(Normal Window)!

    After Resize:
    !http://img863.imageshack.us/img863/5687/hephaistosv30002.png(This is what I want to fix)!

  • Hard to tell. Here are just some thoughts.

    Can you post screenshots?

    How does it behave in Qt Creator when you use form preview?

    Do you have graphics problems on your ubuntu?

    Do you use layouts?

    I hope this helps to find the right direction.

  • Do you use layouts?

  • Thank you for the replies.

    bq. Can you post screenshots?

    Just did (see updated post)

    bq. How does it behave in Qt Creator when you use form preview?

    Since it's a custom widget I don't think I can use it in the form preview (or can I?)

    bq. Do you have graphics problems on your ubuntu?


    bq. Do you use layouts?


    Thanks again

  • bq. Since it’s a custom widget I don’t think I can use it in the form preview (or can I?)

    If you used Qt Creator and took a qwidget as a placeholder and then promote it to your custom widget. Then you can test the placeholder widget in the form preview.

    Could you show us the ui file or code you used for the mainwidget?
    What Qt Creator and Qt version are you using?
    If you just use a qwidget instead of your custom widget. Do you get the same result?

  • Ok I have narrowed the problem down to the buttons on the navigation bar on the left side. They have the following paintEvent function. If I comment it out, the problem goes away:
    @ QStylePainter *p = new QStylePainter(this);
    QStyleOptionToolButton options;
    options.text = text();
    options.icon = icon();
    options.pos = pos();
    options.font = font();
    options.iconSize = iconSize();
    options.toolButtonStyle = this->icon().isNull()?Qt::ToolButtonTextOnly:_side?Qt::ToolButtonTextBesideIcon:Qt::ToolButtonTextUnderIcon;

  • Off topic: It seems you want to copy the style from QtCreator :D

  • You're right that's how I started (a year ago). It was what I knew and what I liked. The functionality has greatly expanded since then and I'm thinking about using a new user interface (it's a miniscule part of the code compared to the backend libraries).

  • I figured it out. The painter cant be a pointer (I should have known that). The icon isn't showing at the moment with the updated code, but I'm sure I can figure that out. Thanks again to everybody.

    EDIT: It worked. Just had to rebuild everything.

Log in to reply