Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    [SOLVED] Add a search QLineEdit to a QTableView

    General and Desktop
    3
    4
    3879
    Loading More Posts
    • 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.
    • F
      frankiefrank last edited by

      I want to implement a basic search box for my QTableView. I'm looking for an elegant solution for placing the lineEdit in reference to the QTableView.

      One way I saw in the documentation was a composite widget (i.e. a QFrame and a layout that would contain both the QTableView and the QLineEdit) but it would be a refactoring hell to have all the table-view methods reimplemented on the level of the new widget.

      Another way I saw was to to just create a widget without a parent/layout and position it "manually" above the QTableView. But I feel like that would be really an ugly way to do it.

      Are there any other solutions I can consider?

      "Roads? Where we're going, we don't need roads."

      1 Reply Last reply Reply Quote 0
      • G
        gmaro last edited by

        Hi,

        This might be a little bit a not-the-best-way but it's easy and quick:
        @
        SearchTableView : public QFrame
        {
        Q_OBJECT
        public:
        WrapperFrame( QWidget parent );
        (const) TableView
        getTableView() (const)

        private:
        TableView *view
        QLineEdit *lineEdit

        //rest of private stuff, search mechanics etc.
        }
        @
        That gives you definitely good layout management instead of absolute positioning.
        In that case you don't need to wrap all the TableView's functions and if need to use many them outside just take the pointer and do what you need.

        1 Reply Last reply Reply Quote 0
        • A
          andre last edited by

          There is another solution. You can use a trick with style sheets to put the search widget inside the table view. What you do is add padding to the widget, and use the cleared out space to put your widget. There is an "example":http://labs.qt.nokia.com/2007/06/06/lineedit-with-a-clear-button/ around on how to put a push button inside a line edit. The principle is the same here.

          1 Reply Last reply Reply Quote 0
          • F
            frankiefrank last edited by

            Thank you very much for your suggestions. Will look into them!

            "Roads? Where we're going, we don't need roads."

            1 Reply Last reply Reply Quote 0
            • First post
              Last post