QWidget editor - force stay on top?



  • Hi,

    I have this current UI:
    https://www.dropbox.com/s/vylw64thx1cnt0c/goodUi.png

    I have a small problem, when I click a row that is in the last 3 rows in the QTableView, the widget editor that is created is hidden inside the QTableView and the user has no way of showing it completely, see problem in action :
    https://www.dropbox.com/s/ij6yonr4m7uk7ii/badUi.png

    Is there an attribute for a QWidget that force it to draw on top of everything else?
    I tried with a few on them without success
    Thanks!

    Code that trigger my QWidget (custom QStyledItemDelegate):
    @QWidget *IntervalDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const

    {
    [...]
    /// Power
    else if (index.column() == 2 ) {
    PowerEditor *editor = new PowerEditor(parent);
    return editor;
    }
    }@

    My QWidget :
    @PowerEditor::PowerEditor(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PowerEditor)
    {
    ui->setupUi(this);

    setAutoFillBackground(true);
    setAttribute(Qt::WA_NoMousePropagation);
    setWindowFlags(Qt::WindowStaysOnTopHint);  //not working..
    

    }@


  • Lifetime Qt Champion

    Hi,

    What OS/Qt combo are you currently using ?



  • Hey,

    The above screenshot is on windows 8.1 latest Qt.
    I have the same behavior happening on OSX Mavericks
    See here :
    https://www.dropbox.com/s/ef2h4olztvmt9po/macOSGUI.png

    Maybe I need to force a vertical scroll bar earlier on the QTableView, when the QTable view has space for 2 more rows, that's when I need to force a vertical Scroll bar and increase QTableView Height, not clean but could work..

    Another thing, the "repeat Widget (widget with the red box)" is different on OSX, seems like there some kind of background line shown on OSX, guess i'm going to have fun making this work for both platform, for example, on OSX my columns seem too small because of the bigger font ;)

    Here is my code when I attach a "Repeat Widget" in the QTableView :
    @ RepeatWidget *repeatWidget = new RepeatWidget(ui->tableView->viewport());
    repeatWidget->id = idRepeatWidget;
    repeatWidget->firstRow = firstIndex.row();
    repeatWidget->lastRow = lastIndex.row();
    repeatWidget->numberRepeat = 2;
    repeatWidget->move(rectCompleteSelection.topLeft());
    repeatWidget->resize(rectCompleteSelection.size().width() + 190, rectCompleteSelection.size().height());
    repeatWidget->show();@

    Thank you



  • I made this little image to show the behavior I would like:
    https://www.dropbox.com/s/9py1vpsovso4eoz/popUpOutsideOk.png

    I would just like to mimic the ContextMenu behavior, when it pop up, is there a specific flag that is set in order to show it on top of all widget?

    Currently, I'm using theses flags on my Widget editor so that it pop up oustide the QtableView, but it's not working

    @ setAutoFillBackground(true);
    setAttribute(Qt::WA_NoMousePropagation);
    setWindowFlags(Qt::WindowStaysOnTopHint);@

    Thanks



  • I tried changing the editor parent to something else, but the same problem still happen.... editor is not top-level.. grr

    @QWidget *IntervalDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const

    {

    /// Power
    if (index.column() == 2 ) {
        PowerEditor *editor = new PowerEditor(parent);
        editor->setWindowFlags(Qt::WindowStaysOnTopHint);
        return editor;
    }@

  • Lifetime Qt Champion

    Since you want a widget that is outside, why not change the paradigm ? Make your editor a dialog and use the mouse events to open it. You can get the item under the mouse cursor and load your editor with it's data



  • I tried changing my custom editor to a QDialog instead of a QWidget. I am not sure what you mean but changing the paradigm; using window pop up when user click a cell? that would be too intrusive IMO, and having to close the editor each time you edit..

    Usually with Qt you can do anything if you are a bit "hacky". This is just a minor bug i'm trying to fix, I don't mind using a workaround, for example; if the popUp stays in the QTableView (like it his now), at least show a VerticalScroll bar so that user access the rest of my editor. Or maybe giving no parent to my editor, and setting the position manually on the cell, that way it is on top of the QTableView?
    Any suggestion, thanks SGaist!

    Here is my editor that I just converted to a QDialog, same behavior:

    @PowerEditor::PowerEditor(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PowerEditor)
    {
    ui->setupUi(this);

    setAutoFillBackground(true);
    setAttribute(Qt::WA_NoMousePropagation);
    setWindowFlags(Qt::WindowStaysOnTopHint);
    
    this->setModal(true);
    
    on_comboBox_power_currentIndexChanged(ui->comboBox_power->currentIndex());
    on_checkBox_balance_toggled(ui->checkBox_balance->isChecked());
    

    }@


  • Lifetime Qt Champion

    What about changing the row height so that your editor fits in ? Then you can use ensureVisible to have it completely on screen and when you're done, you bring it back to a suitable size.



  • I haven't thought of this, great idea! I'll make the row height a bit bigger and change my editor layout more rectangle than square and it should fit in ;)
    ensureVisible is a property of what Widget? google didn't help me much on this one, thanks!


  • Lifetime Qt Champion

    My bad, it's scrollTo with the flag EnsureVisible, I've mixed that with QScrollArea, sorry.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.