Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget created in an aux method does not show/draw

QWidget created in an aux method does not show/draw

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 940 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    utcenter
    wrote on last edited by
    #1

    If I create the widget in the body of its parent widget class it is all good:

    @new NodeWidget(rootItem, this); // this works@

    But when I use the aux method the widget is created, but never drawn.

    @rootItem->createWidget(this); // internally rootItem does the same thing as above@

    The method itself:

    @void createWidget(QWidget * target) {
    if (!_ui) _ui = new NodeWidget(this, target);
    ...
    }@

    The way I see it, both approaches do the same thing, but the first one works while the second one does not. The NodeWidget constructor runs, but the widget does not appear in the parent widget and the paintEvent is never called. Any ideas why?

    EDIT: This is certainly odd, I noticed that the following line:

    @new QPushButton(this);@

    works when called in the constructor of the parent widget, but not when called from the mousePress event. What is the difference?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      What do you mean by "works"? How do you store the new widget in both cases? Do you place the new widget in the parent's layout? Do you call QWidget::show()?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved